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


Java Frameworks类代码示例

本文整理汇总了Java中org.apache.calcite.tools.Frameworks的典型用法代码示例。如果您正苦于以下问题:Java Frameworks类的具体用法?Java Frameworks怎么用?Java Frameworks使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Frameworks类属于org.apache.calcite.tools包,在下文中一共展示了Frameworks类的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: getRootSchema

import org.apache.calcite.tools.Frameworks; //导入依赖的package包/类
private SchemaPlus getRootSchema() throws MetadataStorageManagerException {
    if (rootSchema != null) {
        return rootSchema;
    }
    final SchemaPlus _rootSchema = Frameworks.createRootSchema(true);
    for (String tableSpace : manager.getLocalTableSpaces()) {
        TableSpaceManager tableSpaceManager = manager.getTableSpaceManager(tableSpace);
        SchemaPlus schema = _rootSchema.add(tableSpace, new AbstractSchema());
        List<Table> tables = tableSpaceManager.getAllTablesForPlanner();
        for (Table table : tables) {
            AbstractTableManager tableManager = tableSpaceManager.getTableManager(table.name);
            TableImpl tableDef = new TableImpl(tableManager);
            schema.add(table.name, tableDef);
        }
    }
    rootSchema = _rootSchema;
    return _rootSchema;
}
 
开发者ID:diennea,项目名称:herddb,代码行数:19,代码来源:CalcitePlanner.java

示例3: prepare

import org.apache.calcite.tools.Frameworks; //导入依赖的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);
}
 
开发者ID:apache,项目名称:beam,代码行数:24,代码来源:BeamSqlFnExecutorTestBase.java

示例4: 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

示例5: GremlinCompiler

import org.apache.calcite.tools.Frameworks; //导入依赖的package包/类
public GremlinCompiler(Graph graph, SchemaConfig schemaConfig) {
    this.graph = graph;
    this.schemaConfig = schemaConfig;

    final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
    final List<RelTraitDef> traitDefs = new ArrayList<>();
    traitDefs.add(ConventionTraitDef.INSTANCE);
    traitDefs.add(RelCollationTraitDef.INSTANCE);
    final SqlParser.Config parserConfig =
            SqlParser.configBuilder().setLex(Lex.MYSQL).build();

    frameworkConfig = Frameworks.newConfigBuilder()
            .parserConfig(parserConfig)
            .defaultSchema(rootSchema.add("gremlin", new GremlinSchema(graph, schemaConfig)))
            .traitDefs(traitDefs)
            .programs(Programs.sequence(Programs.ofRules(Programs.RULE_SET), Programs.CALC_PROGRAM))
            .build();
}
 
开发者ID:twilmes,项目名称:sql-gremlin,代码行数:19,代码来源:GremlinCompiler.java

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: perform

import org.apache.calcite.tools.Frameworks; //导入依赖的package包/类
/** Executes a prepare action. */
public <R> R perform(CalciteServerStatement statement,
    Frameworks.PrepareAction<R> action) {
  final CalcitePrepare.Context prepareContext =
      statement.createPrepareContext();
  final JavaTypeFactory typeFactory = prepareContext.getTypeFactory();
  final CalciteSchema schema =
      action.getConfig().getDefaultSchema() != null
          ? CalciteSchema.from(action.getConfig().getDefaultSchema())
          : prepareContext.getRootSchema();
  CalciteCatalogReader catalogReader =
      new CalciteCatalogReader(schema.root(),
          prepareContext.config().caseSensitive(),
          schema.path(null),
          typeFactory);
  final RexBuilder rexBuilder = new RexBuilder(typeFactory);
  final RelOptPlanner planner =
      createPlanner(prepareContext,
          action.getConfig().getContext(),
          action.getConfig().getCostFactory());
  final RelOptCluster cluster = createCluster(planner, rexBuilder);
  return action.apply(cluster, catalogReader,
      prepareContext.getRootSchema().plus(), statement);
}
 
开发者ID:apache,项目名称:kylin,代码行数:25,代码来源:CalcitePrepareImpl.java

示例11: config

import org.apache.calcite.tools.Frameworks; //导入依赖的package包/类
public Frameworks.ConfigBuilder config() throws Exception {
  final Holder<SchemaPlus> root = Holder.of(null);
  CalciteAssert.model(TPCDS_MODEL)
      .doWithConnection(
          new Function<CalciteConnection, Object>() {
            public Object apply(CalciteConnection input) {
              root.set(input.getRootSchema().getSubSchema("TPCDS"));
              return null;
            }
          });
  return Frameworks.newConfigBuilder()
      .parserConfig(SqlParser.Config.DEFAULT)
      .defaultSchema(root.get())
      .traitDefs((List<RelTraitDef>) null)
      .programs(Programs.heuristicJoinOrder(Programs.RULE_SET, true, 2));
}
 
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:TpcdsTest.java

示例12: perform

import org.apache.calcite.tools.Frameworks; //导入依赖的package包/类
/** Executes a prepare action. */
public <R> R perform(CalciteServerStatement statement,
    Frameworks.PrepareAction<R> action) {
  final CalcitePrepare.Context prepareContext =
      statement.createPrepareContext();
  final JavaTypeFactory typeFactory = prepareContext.getTypeFactory();
  final CalciteSchema schema =
      action.getConfig().getDefaultSchema() != null
          ? CalciteSchema.from(action.getConfig().getDefaultSchema())
          : prepareContext.getRootSchema();
  CalciteCatalogReader catalogReader =
      new CalciteCatalogReader(schema.root(),
          schema.path(null),
          typeFactory,
          prepareContext.config());
  final RexBuilder rexBuilder = new RexBuilder(typeFactory);
  final RelOptPlanner planner =
      createPlanner(prepareContext,
          action.getConfig().getContext(),
          action.getConfig().getCostFactory());
  final RelOptCluster cluster = createCluster(planner, rexBuilder);
  return action.apply(cluster, catalogReader,
      prepareContext.getRootSchema().plus(), statement);
}
 
开发者ID:apache,项目名称:calcite,代码行数:25,代码来源:CalcitePrepareImpl.java

示例13: testCollation

import org.apache.calcite.tools.Frameworks; //导入依赖的package包/类
/** Unit test for
 * {@link org.apache.calcite.rel.metadata.RelMdCollation#project}
 * and other helper functions for deducing collations. */
@Test public void testCollation() {
  final Project rel = (Project) convertSql("select * from emp, dept");
  final Join join = (Join) rel.getInput();
  final RelOptTable empTable = join.getInput(0).getTable();
  final RelOptTable deptTable = join.getInput(1).getTable();
  Frameworks.withPlanner(
      new Frameworks.PlannerAction<Void>() {
        public Void apply(RelOptCluster cluster,
            RelOptSchema relOptSchema,
            SchemaPlus rootSchema) {
          checkCollation(cluster, empTable, deptTable);
          return null;
        }
      });
}
 
开发者ID:apache,项目名称:calcite,代码行数:19,代码来源:RelMetadataTest.java

示例14: testAverageRowSize

import org.apache.calcite.tools.Frameworks; //导入依赖的package包/类
/** Unit test for
 * {@link org.apache.calcite.rel.metadata.RelMetadataQuery#getAverageColumnSizes(org.apache.calcite.rel.RelNode)},
 * {@link org.apache.calcite.rel.metadata.RelMetadataQuery#getAverageRowSize(org.apache.calcite.rel.RelNode)}. */
@Test public void testAverageRowSize() {
  final Project rel = (Project) convertSql("select * from emp, dept");
  final Join join = (Join) rel.getInput();
  final RelOptTable empTable = join.getInput(0).getTable();
  final RelOptTable deptTable = join.getInput(1).getTable();
  Frameworks.withPlanner(
      new Frameworks.PlannerAction<Void>() {
        public Void apply(RelOptCluster cluster,
            RelOptSchema relOptSchema,
            SchemaPlus rootSchema) {
          checkAverageRowSize(cluster, empTable, deptTable);
          return null;
        }
      });
}
 
开发者ID:apache,项目名称:calcite,代码行数:19,代码来源:RelMetadataTest.java

示例15: testPredicates

import org.apache.calcite.tools.Frameworks; //导入依赖的package包/类
/** Unit test for
 * {@link org.apache.calcite.rel.metadata.RelMdPredicates#getPredicates(SemiJoin, RelMetadataQuery)}. */
@Test public void testPredicates() {
  final Project rel = (Project) convertSql("select * from emp, dept");
  final Join join = (Join) rel.getInput();
  final RelOptTable empTable = join.getInput(0).getTable();
  final RelOptTable deptTable = join.getInput(1).getTable();
  Frameworks.withPlanner(
      new Frameworks.PlannerAction<Void>() {
        public Void apply(RelOptCluster cluster,
            RelOptSchema relOptSchema,
            SchemaPlus rootSchema) {
          checkPredicates(cluster, empTable, deptTable);
          return null;
        }
      });
}
 
开发者ID:apache,项目名称:calcite,代码行数:18,代码来源:RelMetadataTest.java


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