当前位置: 首页>>代码示例>>Java>>正文


Java Frameworks.getPlanner方法代码示例

本文整理汇总了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();
}
 
开发者ID:jenkin2016,项目名称:solr-sql,代码行数:26,代码来源:SqlTranslatorTest.java

示例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();
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:26,代码来源:SQLExecEnvironment.java

示例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);
}
 
开发者ID:apache,项目名称:samza,代码行数:27,代码来源:SamzaSqlQueryParser.java

示例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);
    }
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:22,代码来源:RuleParser.java

示例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);
    }
  }
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:25,代码来源:StreamlineSqlImpl.java

示例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);
}
 
开发者ID:qubole,项目名称:quark,代码行数:24,代码来源:SqlWorker.java

示例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);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:36,代码来源:DrillSqlWorker.java

示例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);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:35,代码来源:TestSqlBracketlessSyntax.java

示例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);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:35,代码来源:TestSqlBracketlessSyntax.java

示例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));
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:32,代码来源:BeamQueryPlanner.java

示例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);
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:35,代码来源:TestSqlBracketlessSyntax.java

示例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);
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:31,代码来源:TestCompilerUtils.java

示例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);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:34,代码来源:SqlDdlNodes.java

示例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);
}
 
开发者ID:apache,项目名称:calcite,代码行数:14,代码来源:RelToSqlConverterTest.java

示例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);
}
 
开发者ID:apache,项目名称:calcite,代码行数:12,代码来源:LexCaseSensitiveTest.java


注:本文中的org.apache.calcite.tools.Frameworks.getPlanner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。