public CalciteSchema getRootSchema() { return schema.root(); }
public CalciteSchema getRootSchema() { return schema.root(); }
private SqlMonikerImpl moniker(CalciteSchema schema, String name, SqlMonikerType type) { final List<String> path = schema.path(name); if (path.size() == 1 && !schema.root().name.equals("") && type == SqlMonikerType.SCHEMA) { type = SqlMonikerType.CATALOG; } return new SqlMonikerImpl(path, type); }
private SqlMonikerImpl moniker(CalciteSchema schema, String name, SqlMonikerType type) { final List<String> path = schema.path(name); if (path.size() == 1 && !schema.root().name.equals("") && type == SqlMonikerType.SCHEMA) { type = SqlMonikerType.CATALOG; } return new SqlMonikerImpl(path, type); }
/** Allows a sub-class to return an extension of {@link ModifiableViewTable} * by overriding this method. */ protected ModifiableViewTable modifiableViewTable(CalcitePrepare.AnalyzeViewResult parsed, String viewSql, List<String> schemaPath, List<String> viewPath, CalciteSchema schema) { final JavaTypeFactory typeFactory = (JavaTypeFactory) parsed.typeFactory; final Type elementType = typeFactory.getJavaClass(parsed.rowType); return new ModifiableViewTable(elementType, RelDataTypeImpl.proto(parsed.rowType), viewSql, schemaPath, viewPath, parsed.table, Schemas.path(schema.root(), parsed.tablePath), parsed.constraint, parsed.columnMapping); }
/** Allows a sub-class to return an extension of {@link ModifiableViewTable} * by overriding this method. */ protected ModifiableViewTable modifiableViewTable(CalcitePrepare.AnalyzeViewResult parsed, String viewSql, List<String> schemaPath, List<String> viewPath, CalciteSchema schema) { final JavaTypeFactory typeFactory = (JavaTypeFactory) parsed.typeFactory; final Type elementType = typeFactory.getJavaClass(parsed.rowType); return new ModifiableViewTable(elementType, RelDataTypeImpl.proto(parsed.rowType), viewSql, schemaPath, viewPath, parsed.table, Schemas.path(schema.root(), parsed.tablePath), parsed.constraint, parsed.columnMapping); }
/** Converts a relational expression to use a * {@link org.apache.calcite.schema.impl.StarTable} defined in {@code schema}. * Uses the first star table that fits. */ private Iterable<Callback> useStar(CalciteSchema schema, RelNode queryRel) { List<CalciteSchema.TableEntry> starTables = Schemas.getStarTables(schema.root()); if (starTables.isEmpty()) { // Don't waste effort converting to leaf-join form. return ImmutableList.of(); } final List<Callback> list = new ArrayList<>(); final RelNode rel2 = RelOptMaterialization.toLeafJoinForm(queryRel); for (CalciteSchema.TableEntry starTable : starTables) { final Table table = starTable.getTable(); assert table instanceof StarTable; RelOptTableImpl starRelOptTable = RelOptTableImpl.create(catalogReader, table.getRowType(typeFactory), starTable, null); final RelNode rel3 = RelOptMaterialization.tryUseStar(rel2, starRelOptTable); if (rel3 != null) { list.add(new Callback(rel3, starTable, starRelOptTable)); } } return list; }
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()); } });
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); } }
@Override protected ModifiableViewTable modifiableViewTable( CalcitePrepare.AnalyzeViewResult parsed, String viewSql, List<String> schemaPath, List<String> viewPath, CalciteSchema schema) { final JavaTypeFactory typeFactory = (JavaTypeFactory) parsed.typeFactory; final Type elementType = typeFactory.getJavaClass(parsed.rowType); return new MockModifiableViewTable(elementType, RelDataTypeImpl.proto(parsed.rowType), viewSql, schemaPath, viewPath, parsed.table, Schemas.path(schema.root(), parsed.tablePath), parsed.constraint, parsed.columnMapping); } }
@Override protected ModifiableViewTable modifiableViewTable( CalcitePrepare.AnalyzeViewResult parsed, String viewSql, List<String> schemaPath, List<String> viewPath, CalciteSchema schema) { final JavaTypeFactory typeFactory = (JavaTypeFactory) parsed.typeFactory; final Type elementType = typeFactory.getJavaClass(parsed.rowType); return new MockModifiableViewTable(elementType, RelDataTypeImpl.proto(parsed.rowType), viewSql, schemaPath, viewPath, parsed.table, Schemas.path(schema.root(), parsed.tablePath), parsed.constraint, parsed.columnMapping); } }
/** * Creates a context for the purposes of preparing a statement. * * @param connection Connection * @param schema Schema * @param schemaPath Path wherein to look for functions * @param objectPath Path of the object being analyzed (usually a view), * or null * @param propValues Connection properties * @return Context */ private static CalcitePrepare.Context makeContext( CalciteConnection connection, CalciteSchema schema, List<String> schemaPath, List<String> objectPath, final ImmutableMap<CalciteConnectionProperty, String> propValues) { if (connection == null) { final CalcitePrepare.Context context0 = CalcitePrepare.Dummy.peek(); final CalciteConnectionConfig config = mutate(context0.config(), propValues); return makeContext(config, context0.getTypeFactory(), context0.getDataContext(), schema, schemaPath, objectPath); } else { final CalciteConnectionConfig config = mutate(connection.config(), propValues); return makeContext(config, connection.getTypeFactory(), createDataContext(connection, schema.root().plus()), schema, schemaPath, objectPath); } }
/** * Creates a context for the purposes of preparing a statement. * * @param connection Connection * @param schema Schema * @param schemaPath Path wherein to look for functions * @param objectPath Path of the object being analyzed (usually a view), * or null * @param propValues Connection properties * @return Context */ private static CalcitePrepare.Context makeContext( CalciteConnection connection, CalciteSchema schema, List<String> schemaPath, List<String> objectPath, final ImmutableMap<CalciteConnectionProperty, String> propValues) { if (connection == null) { final CalcitePrepare.Context context0 = CalcitePrepare.Dummy.peek(); final CalciteConnectionConfig config = mutate(context0.config(), propValues); return makeContext(config, context0.getTypeFactory(), context0.getDataContext(), schema, schemaPath, objectPath); } else { final CalciteConnectionConfig config = mutate(connection.config(), propValues); return makeContext(config, connection.getTypeFactory(), createDataContext(connection, schema.root().plus()), schema, schemaPath, objectPath); } }
@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()); } };
/** 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(), 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); }