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(); } }
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); }
public CalciteCatalogReader withSchemaPath(List<String> schemaPath) { return new CalciteCatalogReader(rootSchema, nameMatcher, ImmutableList.of(schemaPath, ImmutableList.of()), typeFactory, config); }
public CalciteCatalogReader withSchemaPath(List<String> schemaPath) { return new CalciteCatalogReader(rootSchema, nameMatcher, ImmutableList.of(schemaPath, ImmutableList.of()), typeFactory, config); }
private CalciteCatalogReader createCatalogReader() { SchemaPlus rootSchema = FlinkPlannerImpl.rootSchema(this.defaultSchema); Properties prop = new Properties(); prop.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(parserConfig.caseSensitive())); CalciteConnectionConfig connectionConfig = new CalciteConnectionConfigImpl(prop); return new CalciteCatalogReader( CalciteSchema.from(rootSchema), CalciteSchema.from(this.defaultSchema).path(null), this.typeFactory, connectionConfig); }
private CalciteCatalogReader createCatalogReader(QueryContext context) { return new CalciteCatalogReader( CalciteSchema.from(context.getRootSchema()), false, context.getDefaultSchemaPath(), context.getTypeFactory()); }
private FrameworkConfig buildFrameWorkConfig() { if (hasUdf) { List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>(); sqlOperatorTables.add(SqlStdOperatorTable.instance()); sqlOperatorTables.add(new CalciteCatalogReader(CalciteSchema.from(schema), false, Collections.<String>emptyList(), typeFactory)); return Frameworks.newConfigBuilder().defaultSchema(schema) .operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables)).build(); } else { return Frameworks.newConfigBuilder().defaultSchema(schema).build(); } } }
private CalciteCatalogReader createCatalogReader() { final SchemaPlus rootSchema = rootSchema(defaultSchema); final Context context = config.getContext(); final CalciteConnectionConfig connectionConfig; if (context != null) { connectionConfig = context.unwrap(CalciteConnectionConfig.class); } else { Properties properties = new Properties(); properties.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(parserConfig.caseSensitive())); connectionConfig = new CalciteConnectionConfigImpl(properties); } return new CalciteCatalogReader( CalciteSchema.from(rootSchema), CalciteSchema.from(defaultSchema).path(null), typeFactory, connectionConfig); }
private void visitQuarkTileScan(QuarkTileScan node) { foundOptimizedTableScan.set(true); QuarkTile quarkTile = node.getQuarkTile(); CalciteCatalogReader calciteCatalogReader = new CalciteCatalogReader( CalciteSchema.from(getRootSchma()), false, context.getDefaultSchemaPath(), getTypeFactory()); CalciteSchema tileSchema = calciteCatalogReader.getTable(quarkTile.tableName) .unwrap(CalciteSchema.class); dsBuilder.addAll(getDrivers(tileSchema)); }
private CalciteCatalogReader createCatalogReader() { final SchemaPlus rootSchema = rootSchema(defaultSchema); final Context context = config.getContext(); final CalciteConnectionConfig connectionConfig; if (context != null) { connectionConfig = context.unwrap(CalciteConnectionConfig.class); } else { Properties properties = new Properties(); properties.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(parserConfig.caseSensitive())); connectionConfig = new CalciteConnectionConfigImpl(properties); } return new CalciteCatalogReader( CalciteSchema.from(rootSchema), CalciteSchema.from(defaultSchema).path(null), typeFactory, connectionConfig); }
protected void populateMaterializations(Context context, RelOptPlanner planner, Prepare.Materialization materialization) { // REVIEW: initialize queryRel and tableRel inside MaterializationService, // not here? try { final CalciteSchema schema = materialization.materializedTable.schema; CalciteCatalogReader catalogReader = new CalciteCatalogReader( schema.root(), materialization.viewSchemaPath, context.getTypeFactory(), context.config()); final CalciteMaterializer materializer = new CalciteMaterializer(this, context, catalogReader, schema, planner, createConvertletTable()); materializer.populate(materialization); } catch (Exception e) { throw new RuntimeException("While populating materialization " + materialization.materializedTable.path(), e); } }
protected void populateMaterializations(Context context, RelOptPlanner planner, Prepare.Materialization materialization) { // REVIEW: initialize queryRel and tableRel inside MaterializationService, // not here? try { final CalciteSchema schema = materialization.materializedTable.schema; CalciteCatalogReader catalogReader = new CalciteCatalogReader( schema.root(), materialization.viewSchemaPath, context.getTypeFactory(), context.config()); final CalciteMaterializer materializer = new CalciteMaterializer(this, context, catalogReader, schema, planner, createConvertletTable()); materializer.populate(materialization); } catch (Exception e) { throw new RuntimeException("While populating materialization " + materialization.materializedTable.path(), e); } }
protected void populateMaterializations(Context context, RelOptPlanner planner, Prepare.Materialization materialization) { // REVIEW: initialize queryRel and tableRel inside MaterializationService, // not here? try { final CalciteSchema schema = materialization.materializedTable.schema; CalciteCatalogReader catalogReader = new CalciteCatalogReader( schema.root(), context.config().caseSensitive(), materialization.viewSchemaPath, context.getTypeFactory()); final CalciteMaterializer materializer = new CalciteMaterializer(this, context, catalogReader, schema, planner, createConvertletTable()); materializer.populate(materialization); } catch (Exception e) { throw new RuntimeException("While populating materialization " + materialization.materializedTable.path(), e); } }
private SqlAdvisor getSqlAdvisor() { final CalciteConnectionImpl con = (CalciteConnectionImpl) queryProvider; final String schemaName; try { schemaName = con.getSchema(); } catch (SQLException e) { throw new RuntimeException(e); } final List<String> schemaPath = schemaName == null ? ImmutableList.of() : ImmutableList.of(schemaName); final SqlValidatorWithHints validator = new SqlAdvisorValidator(SqlStdOperatorTable.instance(), new CalciteCatalogReader(rootSchema, schemaPath, typeFactory, con.config()), typeFactory, SqlConformanceEnum.DEFAULT); final CalciteConnectionConfig config = con.config(); // This duplicates org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_ final SqlParser.Config parserConfig = SqlParser.configBuilder() .setQuotedCasing(config.quotedCasing()) .setUnquotedCasing(config.unquotedCasing()) .setQuoting(config.quoting()) .setConformance(config.conformance()) .setCaseSensitive(config.caseSensitive()) .build(); return new SqlAdvisor(validator, parserConfig); }
public static BlinkRelBuilder create(FrameworkConfig config) { JavaTypeFactory typeFactory = new JavaTypeFactoryImpl(config.getTypeSystem()); VolcanoPlanner planner = new VolcanoPlanner(config.getCostFactory(), Contexts.empty()); planner.setExecutor(config.getExecutor()); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); RelOptCluster cluster = RelOptCluster.create(planner, new RexBuilder(typeFactory)); CalciteSchema calciteSchema = CalciteSchema.from(config.getDefaultSchema()); Properties prop = new Properties(); prop.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(config.getParserConfig().caseSensitive())); CalciteConnectionConfig connectionConfig = new CalciteConnectionConfigImpl(prop); RelOptSchema relOptSchema = new CalciteCatalogReader( calciteSchema, CalciteSchema.from(config.getDefaultSchema()).path(null), typeFactory, connectionConfig); return new BlinkRelBuilder(config.getContext(), cluster, relOptSchema); } }
@Override public Table createTable(CalciteSchema schema, String viewSql, List<String> viewSchemaPath) { assert nzTile.tableName != null; CalciteCatalogReader calciteCatalogReader = new CalciteCatalogReader( schema.root(), false, queryContext.getDefaultSchemaPath(), queryContext.getTypeFactory()); CalciteSchema tileSchema = calciteCatalogReader.getTable(nzTile.tableName) .unwrap(CalciteSchema.class); assert tileSchema != null; CalciteSchema.TableEntry tileTEntry = tileSchema.getTable( Util.last(nzTile.tableName), false); assert tileTEntry != null; return new QuarkTileTable(nzTile, calciteCatalogReader, tileTEntry.getTable().getRowType(queryContext.getTypeFactory()), Schemas.path(rootSchema, nzTile.alias), (QuarkTable) tileTEntry.getTable()); } };
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); }
/** 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); }
/** 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); }
/** 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); }