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); }
@Override public CalciteSchema getRootSchema() { return CalciteSchema.from(rootSchema); }
/** Table macro that returns a view. * * @param schema Schema the view will belong to * @param viewSql SQL query * @param schemaPath Path of schema * @param modifiable Whether view is modifiable, or null to deduce it */ public static ViewTableMacro viewMacro(SchemaPlus schema, String viewSql, List<String> schemaPath, List<String> viewPath, Boolean modifiable) { return new ViewTableMacro(CalciteSchema.from(schema), viewSql, schemaPath, viewPath, modifiable); }
/** Table macro that returns a view. * * @param schema Schema the view will belong to * @param viewSql SQL query * @param schemaPath Path of schema * @param modifiable Whether view is modifiable, or null to deduce it */ public static ViewTableMacro viewMacro(SchemaPlus schema, String viewSql, List<String> schemaPath, List<String> viewPath, Boolean modifiable) { return new ViewTableMacro(CalciteSchema.from(schema), viewSql, schemaPath, viewPath, modifiable); }
/** A trojan-horse method, subject to change without notice. */ @VisibleForTesting public static DataContext createDataContext(CalciteConnection connection) { return ((CalciteConnectionImpl) connection) .createDataContext(ImmutableMap.of(), CalciteSchema.from(connection.getRootSchema())); }
/** A trojan-horse method, subject to change without notice. */ @VisibleForTesting public static DataContext createDataContext(CalciteConnection connection) { return ((CalciteConnectionImpl) connection) .createDataContext(ImmutableMap.of(), CalciteSchema.from(connection.getRootSchema())); }
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 ImmutableSet<DataSourceSchema> getDrivers(CalciteSchema tableSchema) { final ImmutableSet.Builder<DataSourceSchema> dsBuilder = new ImmutableSet.Builder<>(); SchemaPlus tableSchemaPlus = tableSchema.plus(); while (tableSchemaPlus != null) { Schema schema = CalciteSchema.from(tableSchemaPlus).schema; if (schema instanceof DataSourceSchema) { dsBuilder.add((DataSourceSchema) schema); } tableSchemaPlus = tableSchemaPlus.getParentSchema(); } return dsBuilder.build(); }
public List<List<String>> getCalciteReaderDefaultPaths(SchemaPlus defaultSchema) { List<List<String>> paths = new ArrayList<>(); // Add both catalog and catalog.db, if there's a default db, as default schema paths paths.add(new ArrayList<>(CalciteSchema.from(defaultSchema).path(getDefaultCatalogName()))); if (getDefaultDatabaseName() != null && defaultSchema.getSubSchema(getDefaultCatalogName()) != null) { paths.add(new ArrayList<>( CalciteSchema.from(defaultSchema.getSubSchema(getDefaultCatalogName())).path(getDefaultDatabaseName()))); } return paths; } }
private void visitNonQuarkScan(TableScan node) { final String schemaName = node.getTable().getQualifiedName().get(0); CalciteSchema schema = CalciteSchema.from(getRootSchma()).getSubSchema(schemaName, false); dsBuilder.addAll(getDrivers(schema)); }
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 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); }
Enumerable<MetaCatalog> catalogs() { return Linq4j.asEnumerable( CalciteSchema.from(getConnection().getRootSchema()).getSubSchemaMap().values()) .select( new Function1<CalciteSchema, MetaCatalog>() { public MetaCatalog apply(CalciteSchema calciteSchema) { return new MetaCatalog(calciteSchema.getName()); } }); }
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 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)); }
public R apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlus rootSchema, CalciteServerStatement statement) { final CalciteSchema schema = CalciteSchema.from( Util.first(config.getDefaultSchema(), rootSchema)); return action.apply(cluster, relOptSchema, schema.root().plus()); } });
public R apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlus rootSchema, CalciteServerStatement statement) { final CalciteSchema schema = CalciteSchema.from( Util.first(config.getDefaultSchema(), rootSchema)); return action.apply(cluster, relOptSchema, schema.root().plus()); } });
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); } }