org.apache.calcite.tools.Frameworks.createRootSchema()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(93)

本文整理了Java中org.apache.calcite.tools.Frameworks.createRootSchema()方法的一些代码示例,展示了Frameworks.createRootSchema()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Frameworks.createRootSchema()方法的具体详情如下:
包路径:org.apache.calcite.tools.Frameworks
类名称:Frameworks
方法名:createRootSchema

Frameworks.createRootSchema介绍

[英]Creates a root schema.
[中]创建根架构。

代码示例

代码示例来源:origin: apache/storm

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, new ColumnConstraint.PrimaryKey(SqlMonotonicity.MONOTONIC, SqlParserPos.ZERO))
    .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"));
  QueryPlanner queryPlanner = new QueryPlanner(schema);
  StreamsRel tree = queryPlanner.getPlan(sql);
  System.out.println(StormRelUtils.explain(tree, SqlExplainLevel.ALL_ATTRIBUTES));
  return new CalciteState(schema, tree);
}

代码示例来源:origin: apache/storm

public static CalciteState sqlOverSimpleEquiJoinTables(String sql)
  throws RelConversionException, ValidationException, SqlParseException {
  SchemaPlus schema = Frameworks.createRootSchema(true);
  JavaTypeFactory typeFactory = new JavaTypeFactoryImpl
    (RelDataTypeSystem.DEFAULT);
  StreamableTable streamableTable = new CompilerUtil.TableBuilderInfo(typeFactory)
    .field("EMPID", SqlTypeName.INTEGER, new ColumnConstraint.PrimaryKey(SqlMonotonicity.MONOTONIC, SqlParserPos.ZERO))
    .field("EMPNAME", SqlTypeName.VARCHAR)
    .field("DEPTID", SqlTypeName.INTEGER)
    .build();
  StreamableTable streamableTable2 = new CompilerUtil.TableBuilderInfo(typeFactory)
    .field("DEPTID", SqlTypeName.INTEGER, new ColumnConstraint.PrimaryKey(SqlMonotonicity.MONOTONIC, SqlParserPos.ZERO))
    .field("DEPTNAME", SqlTypeName.VARCHAR)
    .build();
  Table table = streamableTable.stream();
  Table table2 = streamableTable2.stream();
  schema.add("EMP", table);
  schema.add("DEPT", table2);
  QueryPlanner queryPlanner = new QueryPlanner(schema);
  StreamsRel tree = queryPlanner.getPlan(sql);
  System.out.println(StormRelUtils.explain(tree, SqlExplainLevel.ALL_ATTRIBUTES));
  return new CalciteState(schema, tree);
}

代码示例来源:origin: apache/storm

public static CalciteState sqlOverDummyGroupByTable(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, new ColumnConstraint.PrimaryKey(SqlMonotonicity.MONOTONIC, SqlParserPos.ZERO))
    .field("GRPID", SqlTypeName.INTEGER)
    .field("NAME", typeFactory.createType(String.class))
    .field("ADDR", typeFactory.createType(String.class))
    .field("AGE", SqlTypeName.INTEGER)
    .field("SCORE", SqlTypeName.INTEGER)
    .build();
  Table table = streamableTable.stream();
  schema.add("FOO", table);
  schema.add("BAR", table);
  schema.add("MYSTATICSUM", AggregateFunctionImpl.create(MyStaticSumFunction.class));
  schema.add("MYSUM", AggregateFunctionImpl.create(MySumFunction.class));
  QueryPlanner queryPlanner = new QueryPlanner(schema);
  StreamsRel tree = queryPlanner.getPlan(sql);
  System.out.println(StormRelUtils.explain(tree, SqlExplainLevel.ALL_ATTRIBUTES));
  return new CalciteState(schema, tree);
}

代码示例来源:origin: apache/storm

public static CalciteState sqlOverNestedTable(String sql)
  throws RelConversionException, ValidationException, SqlParseException {
  SchemaPlus schema = Frameworks.createRootSchema(true);
  JavaTypeFactory typeFactory = new JavaTypeFactoryImpl
    (RelDataTypeSystem.DEFAULT);

代码示例来源:origin: org.apache.calcite/calcite-core

Sql(CalciteAssert.SchemaSpec schemaSpec, String sql, SqlDialect dialect,
  SqlToRelConverter.Config config,
  List<Function<RelNode, RelNode>> transforms) {
 final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
 this.schema = CalciteAssert.addSchema(rootSchema, schemaSpec);
 this.sql = sql;
 this.dialect = dialect;
 this.transforms = ImmutableList.copyOf(transforms);
 this.config = config;
}

代码示例来源:origin: Qihoo360/Quicksql

Sql(CalciteAssert.SchemaSpec schemaSpec, String sql, SqlDialect dialect,
  SqlToRelConverter.Config config,
  List<Function<RelNode, RelNode>> transforms) {
 final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
 this.schema = CalciteAssert.addSchema(rootSchema, schemaSpec);
 this.sql = sql;
 this.dialect = dialect;
 this.transforms = ImmutableList.copyOf(transforms);
 this.config = config;
}

代码示例来源:origin: org.apache.calcite/calcite-core

public PrepareAction() {
 this.config = newConfigBuilder() //
   .defaultSchema(Frameworks.createRootSchema(true)).build();
}

代码示例来源:origin: org.apache.calcite/calcite-core

private static SchemaPlus schemaFrom(CalciteAssert.SchemaSpec spec) {
 final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
 return CalciteAssert.addSchema(rootSchema, spec);
}

代码示例来源:origin: Qihoo360/Quicksql

/**
 * Initializes a container then calls user-specified code with a planner.
 *
 * @param action Callback containing user-specified code
 * @return Return value from action
 */
public static <R> R withPlanner(final PlannerAction<R> action) {
 FrameworkConfig config = newConfigBuilder() //
   .defaultSchema(Frameworks.createRootSchema(true)).build();
 return withPlanner(action, config);
}

代码示例来源:origin: org.apache.calcite/calcite-core

/**
 * Initializes a container then calls user-specified code with a planner.
 *
 * @param action Callback containing user-specified code
 * @return Return value from action
 */
public static <R> R withPlanner(final PlannerAction<R> action) {
 FrameworkConfig config = newConfigBuilder() //
   .defaultSchema(Frameworks.createRootSchema(true)).build();
 return withPlanner(action, config);
}

代码示例来源:origin: Qihoo360/Quicksql

/** Unit test to test create root schema which has no "metadata" schema. */
@Test public void testCreateRootSchemaWithNoMetadataSchema() {
 SchemaPlus rootSchema = Frameworks.createRootSchema(false);
 assertThat(rootSchema.getSubSchemaNames().size(), equalTo(0));
}

代码示例来源:origin: org.apache.calcite/calcite-core

/** Unit test to test create root schema which has no "metadata" schema. */
@Test public void testCreateRootSchemaWithNoMetadataSchema() {
 SchemaPlus rootSchema = Frameworks.createRootSchema(false);
 assertThat(rootSchema.getSubSchemaNames().size(), equalTo(0));
}

代码示例来源:origin: Qihoo360/Quicksql

/** Creates a config based on the "scott" schema. */
private static Frameworks.ConfigBuilder config() {
 final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
 return Frameworks.newConfigBuilder()
   .parserConfig(SqlParser.Config.DEFAULT)
   .defaultSchema(CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.SCOTT));
}

代码示例来源:origin: org.apache.calcite/calcite-core

/** Creates a config based on the "scott" schema. */
private static Frameworks.ConfigBuilder config() {
 final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
 return Frameworks.newConfigBuilder()
   .parserConfig(SqlParser.Config.DEFAULT)
   .defaultSchema(CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.SCOTT));
}

代码示例来源:origin: Qihoo360/Quicksql

/** Creates a config based on the "scott" schema. */
public static Frameworks.ConfigBuilder config() {
 final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
 return Frameworks.newConfigBuilder()
   .parserConfig(SqlParser.Config.DEFAULT)
   .defaultSchema(
     CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.SCOTT))
   .traitDefs((List<RelTraitDef>) null)
   .programs(Programs.heuristicJoinOrder(Programs.RULE_SET, true, 2));
}

代码示例来源:origin: org.apache.calcite/calcite-core

/** Creates a config based on the "scott" schema. */
public static Frameworks.ConfigBuilder config() {
 final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
 return Frameworks.newConfigBuilder()
   .parserConfig(SqlParser.Config.DEFAULT)
   .defaultSchema(
     CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.SCOTT))
   .traitDefs((List<RelTraitDef>) null)
   .programs(Programs.heuristicJoinOrder(Programs.RULE_SET, true, 2));
}

代码示例来源:origin: org.apache.calcite/calcite-core

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);
}

代码示例来源:origin: Qihoo360/Quicksql

@Before public void setUp() {
 rootSchema = Frameworks.createRootSchema(true);
 final FrameworkConfig config = Frameworks.newConfigBuilder()
   .parserConfig(SqlParser.Config.DEFAULT)
   .defaultSchema(
     CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.HR))
   .build();
 planner = Frameworks.getPlanner(config);
 dataContext = new MyDataContext(planner);
}

代码示例来源:origin: Qihoo360/Quicksql

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);
}

代码示例来源:origin: org.apache.calcite/calcite-core

@Before public void setUp() {
 rootSchema = Frameworks.createRootSchema(true);
 final FrameworkConfig config = Frameworks.newConfigBuilder()
   .parserConfig(SqlParser.Config.DEFAULT)
   .defaultSchema(
     CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.HR))
   .build();
 planner = Frameworks.getPlanner(config);
 dataContext = new MyDataContext(planner);
}

相关文章