本文整理汇总了Java中org.apache.calcite.tools.FrameworkConfig类的典型用法代码示例。如果您正苦于以下问题:Java FrameworkConfig类的具体用法?Java FrameworkConfig怎么用?Java FrameworkConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FrameworkConfig类属于org.apache.calcite.tools包,在下文中一共展示了FrameworkConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: trans
import org.apache.calcite.tools.FrameworkConfig; //导入依赖的package包/类
private String trans(String sql) throws Exception {
Properties info = new Properties();
info.setProperty("lex", "JAVA");
String jsonFile = SolrSqlTest.class.getClassLoader().getResource("solr.json").toString().replaceAll("file:/", "");
try {
Class.forName("org.apache.calcite.jdbc.Driver");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
CalciteConnection connection = (CalciteConnection) DriverManager.getConnection("jdbc:calcite:model="+jsonFile, info);
final SchemaPlus schema = connection.getRootSchema().getSubSchema("solr");
connection.close();
ConfigBuilder builder = Frameworks.newConfigBuilder().defaultSchema(schema).parserConfig(SqlParser.configBuilder().setCaseSensitive(false).build());
FrameworkConfig config = builder.build();
Planner planner = Frameworks.getPlanner(config);
SqlNode sqlNode = planner.parse(sql);
SqlNode node = planner.validate(sqlNode);
RelRoot relRoot = planner.rel(node);
RelNode project = relRoot.project();
RexNode condition = ((Filter) ((Project) project).getInput()).getCondition();
return _trans.translate(condition).toSolrQueryString();
}
示例2: prepare
import org.apache.calcite.tools.FrameworkConfig; //导入依赖的package包/类
@BeforeClass
public static void prepare() {
relDataType = TYPE_FACTORY.builder()
.add("order_id", SqlTypeName.BIGINT)
.add("site_id", SqlTypeName.INTEGER)
.add("price", SqlTypeName.DOUBLE)
.add("order_time", SqlTypeName.BIGINT).build();
beamRowType = CalciteUtils.toBeamRowType(relDataType);
record = new BeamRecord(beamRowType
, 1234567L, 0, 8.9, 1234567L);
SchemaPlus schema = Frameworks.createRootSchema(true);
final List<RelTraitDef> traitDefs = new ArrayList<>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
FrameworkConfig config = Frameworks.newConfigBuilder()
.parserConfig(SqlParser.configBuilder().setLex(Lex.MYSQL).build()).defaultSchema(schema)
.traitDefs(traitDefs).context(Contexts.EMPTY_CONTEXT).ruleSets(BeamRuleSets.getRuleSets())
.costFactory(null).typeSystem(BeamRelDataTypeSystem.BEAM_REL_DATATYPE_SYSTEM).build();
relBuilder = RelBuilder.create(config);
}
示例3: executeSQL
import org.apache.calcite.tools.FrameworkConfig; //导入依赖的package包/类
/**
* This is the main method takes SQL statement as input and contructs a DAG using contructs registered with this
* {@link SQLExecEnvironment}.
*
* @param sql SQL statement that should be converted to a DAG.
*/
public void executeSQL(DAG dag, String sql)
{
FrameworkConfig config = buildFrameWorkConfig();
Planner planner = Frameworks.getPlanner(config);
try {
logger.info("Parsing SQL statement: {}", sql);
SqlNode parsedTree = planner.parse(sql);
SqlNode validatedTree = planner.validate(parsedTree);
RelNode relationalTree = planner.rel(validatedTree).rel;
logger.info("RelNode relationalTree generate from SQL statement is:\n {}",
Util.toLinux(RelOptUtil.toString(relationalTree)));
RelNodeVisitor visitor = new RelNodeVisitor(dag, typeFactory);
visitor.traverse(relationalTree);
} catch (Exception e) {
throw Throwables.propagate(e);
} finally {
planner.close();
}
}
示例4: createPlanner
import org.apache.calcite.tools.FrameworkConfig; //导入依赖的package包/类
private static Planner createPlanner() {
Connection connection;
SchemaPlus rootSchema;
try {
connection = DriverManager.getConnection("jdbc:calcite:");
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
rootSchema = calciteConnection.getRootSchema();
} catch (SQLException e) {
throw new SamzaException(e);
}
final List<RelTraitDef> traitDefs = new ArrayList<>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder()
.parserConfig(SqlParser.configBuilder().setLex(Lex.JAVA).build())
.defaultSchema(rootSchema)
.operatorTable(SqlStdOperatorTable.instance())
.traitDefs(traitDefs)
.context(Contexts.EMPTY_CONTEXT)
.costFactory(null)
.build();
return Frameworks.getPlanner(frameworkConfig);
}
示例5: parse
import org.apache.calcite.tools.FrameworkConfig; //导入依赖的package包/类
public void parse() {
try {
SchemaPlus schema = Frameworks.createRootSchema(true);
FrameworkConfig config = Frameworks.newConfigBuilder().defaultSchema(schema).build();
Planner planner = Frameworks.getPlanner(config);
SqlSelect sqlSelect = (SqlSelect) planner.parse(sql);
// FROM
streams = parseStreams(sqlSelect);
// SELECT
projection = parseProjection(sqlSelect);
// WHERE
condition = parseCondition(sqlSelect);
// GROUP BY
groupBy = parseGroupBy(sqlSelect);
// HAVING
having = parseHaving(sqlSelect);
} catch (Exception ex) {
LOG.error("Got Exception while parsing rule {}", sql);
throw new RuntimeException(ex);
}
}
示例6: execute
import org.apache.calcite.tools.FrameworkConfig; //导入依赖的package包/类
@Override
public void execute(
Iterable<String> statements, ChannelHandler result)
throws Exception {
Map<String, DataSource> dataSources = new HashMap<>();
for (String sql : statements) {
StreamlineParser parser = new StreamlineParser(sql);
SqlNode node = parser.impl().parseSqlStmtEof();
if (node instanceof SqlCreateTable) {
handleCreateTable((SqlCreateTable) node, dataSources);
} else if (node instanceof SqlCreateFunction) {
handleCreateFunction((SqlCreateFunction) node);
} else {
FrameworkConfig config = buildFrameWorkConfig();
Planner planner = Frameworks.getPlanner(config);
SqlNode parse = planner.parse(sql);
SqlNode validate = planner.validate(parse);
RelNode tree = planner.convert(validate);
PlanCompiler compiler = new PlanCompiler(typeFactory);
AbstractValuesProcessor proc = compiler.compile(tree);
proc.initialize(dataSources, result);
}
}
}
示例7: buildPlanner
import org.apache.calcite.tools.FrameworkConfig; //导入依赖的package包/类
private Planner buildPlanner(QueryContext context) {
final List<RelTraitDef> traitDefs = new ArrayList<RelTraitDef>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
final ChainedSqlOperatorTable opTab =
new ChainedSqlOperatorTable(
ImmutableList.of(SqlStdOperatorTable.instance(),
HiveSqlOperatorTable.instance(), catalogReader));
FrameworkConfig config = Frameworks.newConfigBuilder() //
.parserConfig(SqlParser.configBuilder()
.setQuotedCasing(Casing.UNCHANGED)
.setUnquotedCasing(Casing.TO_UPPER)
.setQuoting(Quoting.DOUBLE_QUOTE)
.build()) //
.defaultSchema(context.getDefaultSchema()) //
.operatorTable(opTab) //
.traitDefs(traitDefs) //
.convertletTable(StandardConvertletTable.INSTANCE)//
.programs(getPrograms()) //
.typeSystem(RelDataTypeSystem.DEFAULT) //
.build();
return Frameworks.getPlanner(config);
}
示例8: testGetPredicatesForJoin
import org.apache.calcite.tools.FrameworkConfig; //导入依赖的package包/类
@Test public void testGetPredicatesForJoin() throws Exception {
final FrameworkConfig config = RelBuilderTest.config().build();
final RelBuilder builder = RelBuilder.create(config);
RelNode join = builder
.scan("EMP")
.scan("DEPT")
.join(JoinRelType.INNER, builder.call(NONDETERMINISTIC_OP))
.build();
RelMetadataQuery mq = RelMetadataQuery.instance();
assertTrue(mq.getPulledUpPredicates(join).pulledUpPredicates.isEmpty());
RelNode join1 = builder
.scan("EMP")
.scan("DEPT")
.join(JoinRelType.INNER,
builder.call(SqlStdOperatorTable.EQUALS,
builder.field(2, 0, 0),
builder.field(2, 1, 0)))
.build();
assertEquals("=($0, $8)",
mq.getPulledUpPredicates(join1).pulledUpPredicates.get(0).toString());
}
示例9: testGetPredicatesForFilter
import org.apache.calcite.tools.FrameworkConfig; //导入依赖的package包/类
@Test public void testGetPredicatesForFilter() throws Exception {
final FrameworkConfig config = RelBuilderTest.config().build();
final RelBuilder builder = RelBuilder.create(config);
RelNode filter = builder
.scan("EMP")
.filter(builder.call(NONDETERMINISTIC_OP))
.build();
RelMetadataQuery mq = RelMetadataQuery.instance();
assertTrue(mq.getPulledUpPredicates(filter).pulledUpPredicates.isEmpty());
RelNode filter1 = builder
.scan("EMP")
.filter(
builder.call(SqlStdOperatorTable.EQUALS,
builder.field(1, 0, 0),
builder.field(1, 0, 1)))
.build();
assertEquals("=($0, $1)",
mq.getPulledUpPredicates(filter1).pulledUpPredicates.get(0).toString());
}
示例10: DrillSqlWorker
import org.apache.calcite.tools.FrameworkConfig; //导入依赖的package包/类
public DrillSqlWorker(QueryContext context) {
final List<RelTraitDef> traitDefs = new ArrayList<RelTraitDef>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(DrillDistributionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
this.context = context;
RelOptCostFactory costFactory = (context.getPlannerSettings().useDefaultCosting()) ?
null : new DrillCostBase.DrillCostFactory() ;
int idMaxLength = (int)context.getPlannerSettings().getIdentifierMaxLength();
FrameworkConfig config = Frameworks.newConfigBuilder() //
.parserConfig(SqlParser.configBuilder()
.setLex(Lex.MYSQL)
.setIdentifierMaxLength(idMaxLength)
.setParserFactory(DrillParserWithCompoundIdConverter.FACTORY)
.build()) //
.defaultSchema(context.getNewDefaultSchema()) //
.operatorTable(context.getDrillOperatorTable()) //
.traitDefs(traitDefs) //
.convertletTable(new DrillConvertletTable()) //
.context(context.getPlannerSettings()) //
.ruleSets(getRules(context)) //
.costFactory(costFactory) //
.executor(new DrillConstExecutor(context.getFunctionRegistry(), context, context.getPlannerSettings()))
.typeSystem(DrillRelDataTypeSystem.DRILL_REL_DATATYPE_SYSTEM) //
.build();
this.planner = Frameworks.getPlanner(config);
HepProgramBuilder builder = new HepProgramBuilder();
builder.addRuleClass(ReduceExpressionsRule.class);
builder.addRuleClass(ProjectToWindowRule.class);
this.hepPlanner = new HepPlanner(builder.build());
hepPlanner.addRule(ReduceExpressionsRule.CALC_INSTANCE);
hepPlanner.addRule(ProjectToWindowRule.PROJECT);
}
示例11: checkComplexExpressionParsing
import org.apache.calcite.tools.FrameworkConfig; //导入依赖的package包/类
@Test
public void checkComplexExpressionParsing() throws Exception{
FrameworkConfig config = Frameworks.newConfigBuilder() //
.parserConfig(SqlParser.configBuilder()
.setLex(Lex.MYSQL)
.setIdentifierMaxLength(PlannerSettings.DEFAULT_IDENTIFIER_MAX_LENGTH)
.setParserFactory(DrillParserImpl.FACTORY)
.build()) //
.defaultSchema(SimpleCalciteSchema.createRootSchema(false)) //
.convertletTable(new DrillConvertletTable()) //
.build();
Planner planner = Frameworks.getPlanner(config);
SqlNode node = planner.parse(""
+ "select a[4].c \n"
+ "from x.y.z \n"
+ "where a.c.b = 5 and x[2] = 7 \n"
+ "group by d \n"
+ "having a.c < 5 \n"
+ "order by x.a.a.a.a.a");
String expected = "SELECT `a`[4]['c']\n" +
"FROM `x`.`y`.`z`\n" +
"WHERE `a`.`c`['b'] = 5 AND `x`[2] = 7\n" +
"GROUP BY `d`\n" +
"HAVING `a`.`c` < 5\n" +
"ORDER BY `x`.`a`['a']['a']['a']['a']";
SqlNode rewritten = node.accept(new CompoundIdentifierConverter());
String rewrittenQuery = rewritten.toString();
DrillAssert.assertMultiLineStringEquals(expected, rewrittenQuery);
}
示例12: checkComplexExpressionParsing
import org.apache.calcite.tools.FrameworkConfig; //导入依赖的package包/类
@Test
public void checkComplexExpressionParsing() throws Exception{
FrameworkConfig config = Frameworks.newConfigBuilder()
.parserConfig(SqlParser.configBuilder()
.setLex(Lex.MYSQL)
.setIdentifierMaxLength(PlannerSettings.DEFAULT_IDENTIFIER_MAX_LENGTH)
.setParserFactory(ParserImpl.FACTORY)
.build())
.defaultSchema(CalciteSchema.createRootSchema(false /* addMetadata */, false /* cache */).plus())
.convertletTable(ConvertletTable.INSTANCE)
.build();
Planner planner = Frameworks.getPlanner(config);
SqlNode node = planner.parse(""
+ "select a[4].c \n"
+ "from x.y.z \n"
+ "where a.c.b = 5 and x[2] = 7 \n"
+ "group by d \n"
+ "having a.c < 5 \n"
+ "order by x.a.a.a.a.a");
String expected = "SELECT `a`[4]['c']\n" +
"FROM `x`.`y`.`z`\n" +
"WHERE `a`.`c`['b'] = 5 AND `x`[2] = 7\n" +
"GROUP BY `d`\n" +
"HAVING `a`.`c` < 5\n" +
"ORDER BY `x`.`a`['a']['a']['a']['a']";
SqlNode rewritten = node.accept(new CompoundIdentifierConverter());
String rewrittenQuery = rewritten.toString();
DremioAssert.assertMultiLineStringEquals(expected, rewrittenQuery);
}
示例13: BeamQueryPlanner
import org.apache.calcite.tools.FrameworkConfig; //导入依赖的package包/类
public BeamQueryPlanner(SchemaPlus schema) {
String defaultCharsetKey = "saffron.default.charset";
if (System.getProperty(defaultCharsetKey) == null) {
System.setProperty(defaultCharsetKey, ConversionUtil.NATIVE_UTF16_CHARSET_NAME);
System.setProperty("saffron.default.nationalcharset",
ConversionUtil.NATIVE_UTF16_CHARSET_NAME);
System.setProperty("saffron.default.collation.name",
String.format("%s$%s", ConversionUtil.NATIVE_UTF16_CHARSET_NAME, "en_US"));
}
final List<RelTraitDef> traitDefs = new ArrayList<>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
sqlOperatorTables.add(SqlStdOperatorTable.instance());
sqlOperatorTables.add(new CalciteCatalogReader(CalciteSchema.from(schema), false,
Collections.<String>emptyList(), TYPE_FACTORY));
FrameworkConfig config = Frameworks.newConfigBuilder()
.parserConfig(SqlParser.configBuilder().setLex(Lex.MYSQL).build()).defaultSchema(schema)
.traitDefs(traitDefs).context(Contexts.EMPTY_CONTEXT).ruleSets(BeamRuleSets.getRuleSets())
.costFactory(null).typeSystem(BeamRelDataTypeSystem.BEAM_REL_DATATYPE_SYSTEM)
.operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables))
.build();
this.planner = Frameworks.getPlanner(config);
for (String t : schema.getTableNames()) {
sourceTables.put(t, (BaseBeamTable) schema.getTable(t));
}
}
示例14: checkComplexExpressionParsing
import org.apache.calcite.tools.FrameworkConfig; //导入依赖的package包/类
@Test
public void checkComplexExpressionParsing() throws Exception{
FrameworkConfig config = Frameworks.newConfigBuilder() //
.parserConfig(SqlParser.configBuilder()
.setLex(Lex.MYSQL)
.setIdentifierMaxLength(PlannerSettings.DEFAULT_IDENTIFIER_MAX_LENGTH)
.setParserFactory(DrillParserImpl.FACTORY)
.build()) //
.defaultSchema(SimpleCalciteSchema.createRootSchema(false)) //
.convertletTable(DrillConvertletTable.INSTANCE) //
.build();
Planner planner = Frameworks.getPlanner(config);
SqlNode node = planner.parse(""
+ "select a[4].c \n"
+ "from x.y.z \n"
+ "where a.c.b = 5 and x[2] = 7 \n"
+ "group by d \n"
+ "having a.c < 5 \n"
+ "order by x.a.a.a.a.a");
String expected = "SELECT `a`[4]['c']\n" +
"FROM `x`.`y`.`z`\n" +
"WHERE `a`.`c`['b'] = 5 AND `x`[2] = 7\n" +
"GROUP BY `d`\n" +
"HAVING `a`.`c` < 5\n" +
"ORDER BY `x`.`a`['a']['a']['a']['a']";
SqlNode rewritten = node.accept(new CompoundIdentifierConverter());
String rewrittenQuery = rewritten.toString();
DrillAssert.assertMultiLineStringEquals(expected, rewrittenQuery);
}
示例15: buildFrameWorkConfig
import org.apache.calcite.tools.FrameworkConfig; //导入依赖的package包/类
/**
* Method method build a calcite framework configuration for calcite to parse SQL and generate relational tree
* out of it.
* @return FrameworkConfig
*/
private FrameworkConfig buildFrameWorkConfig()
{
List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
sqlOperatorTables.add(SqlStdOperatorTable.instance());
sqlOperatorTables
.add(new CalciteCatalogReader(CalciteSchema.from(schema), false, Collections.<String>emptyList(), typeFactory));
return Frameworks.newConfigBuilder().defaultSchema(schema)
.parserConfig(SqlParser.configBuilder().setLex(Lex.MYSQL).build())
.operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables)).build();
}