本文整理了Java中org.apache.calcite.tools.Frameworks
类的一些代码示例,展示了Frameworks
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Frameworks
类的具体详情如下:
包路径:org.apache.calcite.tools.Frameworks
类名称:Frameworks
[英]Tools for invoking Calcite functionality without initializing a container / server first.
[中]无需首先初始化容器/服务器即可调用方解石功能的工具。
代码示例来源:origin: apache/storm
public QueryPlanner(SchemaPlus schema) {
final List<RelTraitDef> traitDefs = new ArrayList<RelTraitDef>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
sqlOperatorTables.add(SqlStdOperatorTable.instance());
sqlOperatorTables.add(new CalciteCatalogReader(CalciteSchema.from(schema),
Collections.emptyList(), typeFactory, new CalciteConnectionConfigImpl(new Properties())));
FrameworkConfig config = Frameworks.newConfigBuilder()
.defaultSchema(schema)
.operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables))
.traitDefs(traitDefs)
.context(Contexts.EMPTY_CONTEXT)
.ruleSets(StreamsStormRuleSets.getRuleSets())
.costFactory(null)
.typeSystem(StormRelDataTypeSystem.STORM_REL_DATATYPE_SYSTEM)
.build();
this.planner = Frameworks.getPlanner(config);
}
代码示例来源: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/drill
/**
* Get optimized logical plan for the given QB tree in the semAnalyzer.
*
* @return
* @throws SemanticException
*/
RelNode logicalPlan() throws SemanticException {
RelNode optimizedOptiqPlan = null;
CalcitePlannerAction calcitePlannerAction = null;
if (this.columnAccessInfo == null) {
this.columnAccessInfo = new ColumnAccessInfo();
}
calcitePlannerAction = new CalcitePlannerAction(prunedPartitions, this.columnAccessInfo);
try {
optimizedOptiqPlan = Frameworks.withPlanner(calcitePlannerAction, Frameworks
.newConfigBuilder().typeSystem(new HiveTypeSystemImpl()).build());
} catch (Exception e) {
rethrowCalciteException(e);
throw new AssertionError("rethrowCalciteException didn't throw for " + e.getMessage());
}
return optimizedOptiqPlan;
}
代码示例来源:origin: hortonworks/streamline
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);
}
}
代码示例来源:origin: org.apache.calcite/calcite-core
public PrepareAction() {
this.config = newConfigBuilder() //
.defaultSchema(Frameworks.createRootSchema(true)).build();
}
代码示例来源:origin: apache/storm
public FrameworkConfig buildFrameWorkConfig() {
if (hasUdf) {
List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
sqlOperatorTables.add(SqlStdOperatorTable.instance());
sqlOperatorTables.add(new CalciteCatalogReader(CalciteSchema.from(schema),
Collections.emptyList(), typeFactory, new CalciteConnectionConfigImpl(new Properties())));
return Frameworks.newConfigBuilder().defaultSchema(schema)
.operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables)).build();
} else {
return Frameworks.newConfigBuilder().defaultSchema(schema).build();
}
}
代码示例来源: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: apache/storm
public String explain(String query) throws SqlParseException, ValidationException, RelConversionException {
FrameworkConfig config = buildFrameWorkConfig();
Planner planner = Frameworks.getPlanner(config);
SqlNode parse = planner.parse(query);
SqlNode validate = planner.validate(parse);
RelNode tree = planner.convert(validate);
return StormRelUtils.explain(tree, SqlExplainLevel.ALL_ATTRIBUTES);
}
代码示例来源:origin: Qihoo360/Quicksql
private void ready() {
switch (state) {
case STATE_0_CLOSED:
reset();
}
ensure(State.STATE_1_RESET);
Frameworks.withPlanner(
(cluster, relOptSchema, rootSchema) -> {
Util.discard(rootSchema); // use our own defaultSchema
typeFactory = (JavaTypeFactory) cluster.getTypeFactory();
planner = cluster.getPlanner();
planner.setExecutor(executor);
return null;
},
config);
state = State.STATE_2_READY;
// If user specify own traitDef, instead of default default trait,
// first, clear the default trait def registered with planner
// then, register the trait def specified in traitDefs.
if (this.traitDefs != null) {
planner.clearRelTraitDefs();
for (RelTraitDef def : this.traitDefs) {
planner.addRelTraitDef(def);
}
}
}
代码示例来源:origin: apache/hive
/** Creates a RelBuilder. */
public static HiveSubQRemoveRelBuilder create(FrameworkConfig config) {
final RelOptCluster[] clusters = {null};
final RelOptSchema[] relOptSchemas = {null};
Frameworks.withPrepare(
new Frameworks.PrepareAction<Void>(config) {
public Void apply(RelOptCluster cluster, RelOptSchema relOptSchema,
SchemaPlus rootSchema, CalciteServerStatement statement) {
clusters[0] = cluster;
relOptSchemas[0] = relOptSchema;
return null;
}
});
return new HiveSubQRemoveRelBuilder(config.getContext(), clusters[0], relOptSchemas[0]);
}
代码示例来源: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
public PrepareAction() {
this.config = newConfigBuilder() //
.defaultSchema(Frameworks.createRootSchema(true)).build();
}
代码示例来源:origin: org.apache.calcite/calcite-core
private Frameworks.ConfigBuilder builder() {
return Frameworks.newConfigBuilder(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: twilmes/sql-gremlin
public QueryPlanner(final FrameworkConfig frameworkConfig) {
this.planner = Frameworks.getPlanner(frameworkConfig);
}
代码示例来源:origin: org.apache.calcite/calcite-core
private void ready() {
switch (state) {
case STATE_0_CLOSED:
reset();
}
ensure(State.STATE_1_RESET);
Frameworks.withPlanner(
(cluster, relOptSchema, rootSchema) -> {
Util.discard(rootSchema); // use our own defaultSchema
typeFactory = (JavaTypeFactory) cluster.getTypeFactory();
planner = cluster.getPlanner();
planner.setExecutor(executor);
return null;
},
config);
state = State.STATE_2_READY;
// If user specify own traitDef, instead of default default trait,
// first, clear the default trait def registered with planner
// then, register the trait def specified in traitDefs.
if (this.traitDefs != null) {
planner.clearRelTraitDefs();
for (RelTraitDef def : this.traitDefs) {
planner.addRelTraitDef(def);
}
}
}
代码示例来源:origin: apache/hive
/** Creates a RelBuilder. */
public static RelBuilder create(FrameworkConfig config) {
final RelOptCluster[] clusters = {null};
final RelOptSchema[] relOptSchemas = {null};
Frameworks.withPrepare(
new Frameworks.PrepareAction<Void>(config) {
public Void apply(RelOptCluster cluster, RelOptSchema relOptSchema,
SchemaPlus rootSchema, CalciteServerStatement statement) {
clusters[0] = cluster;
relOptSchemas[0] = relOptSchema;
return null;
}
});
return new HiveRelBuilder(config.getContext(), clusters[0], relOptSchemas[0]);
}
代码示例来源: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
/** 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: apache/incubator-druid
.build();
final FrameworkConfig frameworkConfig = Frameworks
.newConfigBuilder()
.parserConfig(PARSER_CONFIG)
.traitDefs(ConventionTraitDef.INSTANCE, RelCollationTraitDef.INSTANCE)
.convertletTable(new DruidConvertletTable(plannerContext))
.operatorTable(operatorTable)
.programs(Rules.programs(plannerContext, queryMaker))
Frameworks.getPlanner(frameworkConfig),
plannerContext
);
内容来源于网络,如有侵权,请联系作者删除!