本文整理汇总了Java中org.apache.calcite.tools.Frameworks.getPlanner方法的典型用法代码示例。如果您正苦于以下问题:Java Frameworks.getPlanner方法的具体用法?Java Frameworks.getPlanner怎么用?Java Frameworks.getPlanner使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.tools.Frameworks
的用法示例。
在下文中一共展示了Frameworks.getPlanner方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: trans
import org.apache.calcite.tools.Frameworks; //导入方法依赖的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: executeSQL
import org.apache.calcite.tools.Frameworks; //导入方法依赖的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();
}
}
示例3: createPlanner
import org.apache.calcite.tools.Frameworks; //导入方法依赖的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);
}
示例4: parse
import org.apache.calcite.tools.Frameworks; //导入方法依赖的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);
}
}
示例5: execute
import org.apache.calcite.tools.Frameworks; //导入方法依赖的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);
}
}
}
示例6: buildPlanner
import org.apache.calcite.tools.Frameworks; //导入方法依赖的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);
}
示例7: DrillSqlWorker
import org.apache.calcite.tools.Frameworks; //导入方法依赖的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);
}
示例8: checkComplexExpressionParsing
import org.apache.calcite.tools.Frameworks; //导入方法依赖的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);
}
示例9: checkComplexExpressionParsing
import org.apache.calcite.tools.Frameworks; //导入方法依赖的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);
}
示例10: BeamQueryPlanner
import org.apache.calcite.tools.Frameworks; //导入方法依赖的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));
}
}
示例11: checkComplexExpressionParsing
import org.apache.calcite.tools.Frameworks; //导入方法依赖的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);
}
示例12: sqlOverDummyTable
import org.apache.calcite.tools.Frameworks; //导入方法依赖的package包/类
public static CalciteState sqlOverDummyTable(String sql)
throws RelConversionException, ValidationException, SqlParseException {
SchemaPlus schema = Frameworks.createRootSchema(true);
JavaTypeFactory typeFactory = new JavaTypeFactoryImpl
(RelDataTypeSystem.DEFAULT);
StreamableTable streamableTable = new CompilerUtil.TableBuilderInfo(typeFactory)
.field("ID", SqlTypeName.INTEGER)
.field("NAME", typeFactory.createType(String.class))
.field("ADDR", typeFactory.createType(String.class))
.build();
Table table = streamableTable.stream();
schema.add("FOO", table);
schema.add("BAR", table);
schema.add("MYPLUS", ScalarFunctionImpl.create(MyPlus.class, "eval"));
List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
sqlOperatorTables.add(SqlStdOperatorTable.instance());
sqlOperatorTables.add(new CalciteCatalogReader(CalciteSchema.from(schema),
false,
Collections.<String>emptyList(), typeFactory));
SqlOperatorTable chainedSqlOperatorTable = new ChainedSqlOperatorTable(sqlOperatorTables);
FrameworkConfig config = Frameworks.newConfigBuilder().defaultSchema(
schema).operatorTable(chainedSqlOperatorTable).build();
Planner planner = Frameworks.getPlanner(config);
SqlNode parse = planner.parse(sql);
SqlNode validate = planner.validate(parse);
RelNode tree = planner.convert(validate);
System.out.println(RelOptUtil.toString(tree, SqlExplainLevel.ALL_ATTRIBUTES));
return new CalciteState(schema, tree);
}
示例13: populate
import org.apache.calcite.tools.Frameworks; //导入方法依赖的package包/类
/** Populates the table called {@code name} by executing {@code query}. */
protected static void populate(SqlIdentifier name, SqlNode query,
CalcitePrepare.Context context) {
// Generate, prepare and execute an "INSERT INTO table query" statement.
// (It's a bit inefficient that we convert from SqlNode to SQL and back
// again.)
final FrameworkConfig config = Frameworks.newConfigBuilder()
.defaultSchema(context.getRootSchema().plus())
.build();
final Planner planner = Frameworks.getPlanner(config);
try {
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
final SqlPrettyWriter w =
new SqlPrettyWriter(CalciteSqlDialect.DEFAULT, false, pw);
pw.print("INSERT INTO ");
name.unparse(w, 0, 0);
pw.print(" ");
query.unparse(w, 0, 0);
pw.flush();
final String sql = sw.toString();
final SqlNode query1 = planner.parse(sql);
final SqlNode query2 = planner.validate(query1);
final RelRoot r = planner.rel(query2);
final PreparedStatement prepare = context.getRelRunner().prepare(r.rel);
int rowCount = prepare.executeUpdate();
Util.discard(rowCount);
prepare.close();
} catch (SqlParseException | ValidationException
| RelConversionException | SQLException e) {
throw new RuntimeException(e);
}
}
示例14: getPlanner
import org.apache.calcite.tools.Frameworks; //导入方法依赖的package包/类
private static Planner getPlanner(List<RelTraitDef> traitDefs,
SqlParser.Config parserConfig, CalciteAssert.SchemaSpec schemaSpec,
SqlToRelConverter.Config sqlToRelConf, Program... programs) {
final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
final FrameworkConfig config = Frameworks.newConfigBuilder()
.parserConfig(parserConfig)
.defaultSchema(CalciteAssert.addSchema(rootSchema, schemaSpec))
.traitDefs(traitDefs)
.sqlToRelConverterConfig(sqlToRelConf)
.programs(programs)
.build();
return Frameworks.getPlanner(config);
}
示例15: getPlanner
import org.apache.calcite.tools.Frameworks; //导入方法依赖的package包/类
private static Planner getPlanner(List<RelTraitDef> traitDefs,
SqlParser.Config parserConfig, Program... programs) {
final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
final FrameworkConfig config = Frameworks.newConfigBuilder()
.parserConfig(parserConfig)
.defaultSchema(CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.HR))
.traitDefs(traitDefs)
.programs(programs)
.build();
return Frameworks.getPlanner(config);
}