/** Returns this object's path. For example ["hr", "emps"]. */ public final List<String> path() { return schema.path(name); } }
public List<String> getDefaultSchemaPath() { // schemaPath is usually null. If specified, it overrides schema // as the context within which the SQL is validated. if (schemaPath == null) { return schema.path(null); } return schemaPath; }
/** Returns this object's path. For example ["hr", "emps"]. */ public final List<String> path() { return schema.path(name); } }
public List<String> getDefaultSchemaPath() { // schemaPath is usually null. If specified, it overrides schema // as the context within which the SQL is validated. if (schemaPath == null) { return schema.path(null); } return schemaPath; }
/** Returns the default path resolving functions from this schema. * * <p>The path consists is a list of lists of strings. * Each list of strings represents the path of a schema from the root schema. * For example, [[], [foo], [foo, bar, baz]] represents three schemas: the * root schema "/" (level 0), "/foo" (level 1) and "/foo/bar/baz" (level 3). * * @return Path of this schema; never null, may be empty */ public List<? extends List<String>> getPath() { if (path != null) { return path; } // Return a path consisting of just this schema. return ImmutableList.of(path(null)); }
/** Returns the default path resolving functions from this schema. * * <p>The path consists is a list of lists of strings. * Each list of strings represents the path of a schema from the root schema. * For example, [[], [foo], [foo, bar, baz]] represents three schemas: the * root schema "/" (level 0), "/foo" (level 1) and "/foo/bar/baz" (level 3). * * @return Path of this schema; never null, may be empty */ public List<? extends List<String>> getPath() { if (path != null) { return path; } // Return a path consisting of just this schema. return ImmutableList.of(path(null)); }
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); }
private MaterializedViewTableMacro(CalciteSchema schema, String viewSql, List<String> viewSchemaPath, List<String> viewPath, String suggestedTableName, boolean existing) { super(schema, viewSql, viewSchemaPath != null ? viewSchemaPath : schema.path(null), viewPath, Boolean.TRUE); this.key = Objects.requireNonNull( MaterializationService.instance().defineMaterialization( schema, null, viewSql, schemaPath, suggestedTableName, true, existing)); }
private MaterializedViewTableMacro(CalciteSchema schema, String viewSql, List<String> viewSchemaPath, List<String> viewPath, String suggestedTableName, boolean existing) { super(schema, viewSql, viewSchemaPath != null ? viewSchemaPath : schema.path(null), viewPath, Boolean.TRUE); this.key = Objects.requireNonNull( MaterializationService.instance().defineMaterialization( schema, null, viewSql, schemaPath, suggestedTableName, true, existing)); }
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 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); }
public TranslatableTable apply(List<Object> arguments) { final CalciteConnection connection = MaterializedViewTable.MATERIALIZATION_CONNECTION; CalcitePrepare.AnalyzeViewResult parsed = Schemas.analyzeView(connection, schema, schemaPath, viewSql, viewPath, modifiable != null && modifiable); final List<String> schemaPath1 = schemaPath != null ? schemaPath : schema.path(null); if ((modifiable == null || modifiable) && parsed.modifiable && parsed.table != null) { return modifiableViewTable(parsed, viewSql, schemaPath1, viewPath, schema); } else { return viewTable(parsed, viewSql, schemaPath1, viewPath); } }
public TranslatableTable apply(List<Object> arguments) { final CalciteConnection connection = MaterializedViewTable.MATERIALIZATION_CONNECTION; CalcitePrepare.AnalyzeViewResult parsed = Schemas.analyzeView(connection, schema, schemaPath, viewSql, viewPath, modifiable != null && modifiable); final List<String> schemaPath1 = schemaPath != null ? schemaPath : schema.path(null); if ((modifiable == null || modifiable) && parsed.modifiable && parsed.table != null) { return modifiableViewTable(parsed, viewSql, schemaPath1, viewPath, schema); } else { return viewTable(parsed, viewSql, schemaPath1, viewPath); } }
@Override public TranslatableTable apply(List<Object> arguments) { assert arguments.isEmpty(); CalcitePrepare.ParseResult parsed = Schemas.parse(MATERIALIZATION_CONNECTION, schema, schemaPath, viewSql); final List<String> schemaPath1 = schemaPath != null ? schemaPath : schema.path(null); final JavaTypeFactory typeFactory = MATERIALIZATION_CONNECTION.getTypeFactory(); return new MaterializedViewTable(typeFactory.getJavaClass(parsed.rowType), RelDataTypeImpl.proto(parsed.rowType), viewSql, schemaPath1, viewPath, key); } }
@Override public TranslatableTable apply(List<Object> arguments) { assert arguments.isEmpty(); CalcitePrepare.ParseResult parsed = Schemas.parse(MATERIALIZATION_CONNECTION, schema, schemaPath, viewSql); final List<String> schemaPath1 = schemaPath != null ? schemaPath : schema.path(null); final JavaTypeFactory typeFactory = MATERIALIZATION_CONNECTION.getTypeFactory(); return new MaterializedViewTable(typeFactory.getJavaClass(parsed.rowType), RelDataTypeImpl.proto(parsed.rowType), viewSql, schemaPath1, viewPath, key); } }
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); }
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); } }
/** 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); }