use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.FrameworkConfig in project druid by druid-io.
the class PlannerFactory method createPlanner.
public DruidPlanner createPlanner(final Map<String, Object> queryContext) {
final PlannerContext plannerContext = PlannerContext.create(plannerConfig, queryContext);
final QueryMaker queryMaker = new QueryMaker(walker, plannerContext);
final FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder().parserConfig(SqlParser.configBuilder().setCaseSensitive(true).setUnquotedCasing(Casing.UNCHANGED).setQuotedCasing(Casing.UNCHANGED).setQuoting(Quoting.DOUBLE_QUOTE).build()).defaultSchema(rootSchema).traitDefs(ConventionTraitDef.INSTANCE, RelCollationTraitDef.INSTANCE).convertletTable(new DruidConvertletTable(plannerContext)).operatorTable(operatorTable).programs(Rules.programs(queryMaker, operatorTable)).executor(new RexExecutorImpl(Schemas.createDataContext(null))).context(Contexts.EMPTY_CONTEXT).typeSystem(RelDataTypeSystem.DEFAULT).defaultSchema(rootSchema.getSubSchema(DruidSchema.NAME)).build();
return new DruidPlanner(Frameworks.getPlanner(frameworkConfig), plannerContext);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.FrameworkConfig in project streamline by hortonworks.
the class TestCompilerUtils method sqlOverDummyTable.
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);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.FrameworkConfig in project streamline by hortonworks.
the class StreamlineSqlImpl method execute.
@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);
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.FrameworkConfig in project herddb by diennea.
the class CalcitePlanner method runPlanner.
private PlannerResult runPlanner(String defaultTableSpace, String query) throws RelConversionException, SqlParseException, ValidationException, MetadataStorageManagerException {
SchemaPlus subSchema = getSchemaForTableSpace(defaultTableSpace);
if (subSchema == null) {
TableSpaceManager tableSpaceManager = manager.getTableSpaceManager(defaultTableSpace);
clearCache();
throw new StatementExecutionException("internal error," + "Calcite subSchema for " + defaultTableSpace + " is null," + "tableSpaceManager is " + tableSpaceManager + "," + "maybe table space " + defaultTableSpace + " is not yet started on this node");
}
final FrameworkConfig config = Frameworks.newConfigBuilder().parserConfig(SQL_PARSER_CONFIG).defaultSchema(subSchema).traitDefs(TRAITS).programs(Programs.ofRules(Programs.RULE_SET)).build();
Planner planner = Frameworks.getPlanner(config);
if (LOG.isLoggable(Level.FINER)) {
LOG.log(Level.FINER, "Query: {0}", query);
}
SqlNode n = planner.parse(query);
n = planner.validate(n);
RelNode logicalPlan = planner.rel(n).project();
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Query: {0} {1}", new Object[] { query, RelOptUtil.dumpPlan("-- Logical Plan", logicalPlan, SqlExplainFormat.TEXT, SqlExplainLevel.ALL_ATTRIBUTES) });
}
RelDataType originalRowType = logicalPlan.getRowType();
RelOptCluster cluster = logicalPlan.getCluster();
final RelOptPlanner optPlanner = cluster.getPlanner();
RelTraitSet desiredTraits = cluster.traitSet().replace(EnumerableConvention.INSTANCE);
final RelNode newRoot = optPlanner.changeTraits(logicalPlan, desiredTraits);
optPlanner.setRoot(newRoot);
RelNode bestExp = optPlanner.findBestExp();
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Query: {0} {1}", new Object[] { query, RelOptUtil.dumpPlan("-- Best Plan", bestExp, SqlExplainFormat.TEXT, SqlExplainLevel.ALL_ATTRIBUTES) });
}
// SqlExplainLevel.ALL_ATTRIBUTES));
return new PlannerResult(bestExp, originalRowType, logicalPlan);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.FrameworkConfig in project samza by apache.
the class QueryPlanner method getPlanner.
private Planner getPlanner() {
Planner planner = null;
try {
Connection connection = DriverManager.getConnection("jdbc:calcite:");
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
registerSourceSchemas(rootSchema);
List<SamzaSqlScalarFunctionImpl> samzaSqlFunctions = udfMetadata.stream().map(SamzaSqlScalarFunctionImpl::new).collect(Collectors.toList());
final List<RelTraitDef> traitDefs = new ArrayList<>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
sqlOperatorTables.add(new SamzaSqlOperatorTable());
sqlOperatorTables.add(new SamzaSqlUdfOperatorTable(samzaSqlFunctions));
// TODO: Introduce a pluggable rule factory.
List<RelOptRule> rules = ImmutableList.of(FilterProjectTransposeRule.INSTANCE, ProjectMergeRule.INSTANCE, new SamzaSqlFilterRemoteJoinRule.SamzaSqlFilterIntoRemoteJoinRule(true, RelFactories.LOGICAL_BUILDER, systemStreamConfigBySource));
// Using lenient so that !=,%,- are allowed.
FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder().parserConfig(SqlParser.configBuilder().setLex(Lex.JAVA).setConformance(SqlConformanceEnum.LENIENT).setCaseSensitive(// Make Udfs case insensitive
false).build()).defaultSchema(rootSchema).operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables)).sqlToRelConverterConfig(SqlToRelConverter.Config.DEFAULT).traitDefs(traitDefs).programs(Programs.hep(rules, true, DefaultRelMetadataProvider.INSTANCE)).build();
planner = Frameworks.getPlanner(frameworkConfig);
return planner;
} catch (Exception e) {
String errorMsg = "Failed to create planner.";
LOG.error(errorMsg, e);
if (planner != null) {
planner.close();
}
throw new SamzaException(errorMsg, e);
}
}
Aggregations