Search in sources :

Example 1 with Wrapper

use of org.apache.calcite.schema.Wrapper in project calcite by apache.

the class SqlDropMaterializedView method execute.

@Override
public void execute(CalcitePrepare.Context context) {
    final Pair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, name);
    final Table table = pair.left.plus().getTable(pair.right);
    if (table != null) {
        // Materialized view exists.
        super.execute(context);
        if (table instanceof Wrapper) {
            final MaterializationKey materializationKey = ((Wrapper) table).unwrap(MaterializationKey.class);
            if (materializationKey != null) {
                MaterializationService.instance().removeMaterialization(materializationKey);
            }
        }
    }
}
Also used : Wrapper(org.apache.calcite.schema.Wrapper) Table(org.apache.calcite.schema.Table) MaterializationKey(org.apache.calcite.materialize.MaterializationKey) CalciteSchema(org.apache.calcite.jdbc.CalciteSchema)

Example 2 with Wrapper

use of org.apache.calcite.schema.Wrapper in project calcite by apache.

the class EmptyScope method resolve_.

private void resolve_(final CalciteSchema rootSchema, List<String> names, List<String> schemaNames, SqlNameMatcher nameMatcher, Path path, Resolved resolved) {
    final List<String> concat = ImmutableList.<String>builder().addAll(schemaNames).addAll(names).build();
    CalciteSchema schema = rootSchema;
    SqlValidatorNamespace namespace = null;
    List<String> remainingNames = concat;
    for (String schemaName : concat) {
        if (schema == rootSchema && nameMatcher.matches(schemaName, schema.name)) {
            remainingNames = Util.skip(remainingNames);
            continue;
        }
        final CalciteSchema subSchema = schema.getSubSchema(schemaName, nameMatcher.isCaseSensitive());
        if (subSchema != null) {
            path = path.plus(null, -1, subSchema.name, StructKind.NONE);
            remainingNames = Util.skip(remainingNames);
            schema = subSchema;
            namespace = new SchemaNamespace(validator, ImmutableList.copyOf(path.stepNames()));
            continue;
        }
        CalciteSchema.TableEntry entry = schema.getTable(schemaName, nameMatcher.isCaseSensitive());
        if (entry == null) {
            entry = schema.getTableBasedOnNullaryFunction(schemaName, nameMatcher.isCaseSensitive());
        }
        if (entry != null) {
            path = path.plus(null, -1, entry.name, StructKind.NONE);
            remainingNames = Util.skip(remainingNames);
            final Table table = entry.getTable();
            SqlValidatorTable table2 = null;
            if (table instanceof Wrapper) {
                table2 = ((Wrapper) table).unwrap(Prepare.PreparingTable.class);
            }
            if (table2 == null) {
                final RelOptSchema relOptSchema = validator.catalogReader.unwrap(RelOptSchema.class);
                final RelDataType rowType = table.getRowType(validator.typeFactory);
                table2 = RelOptTableImpl.create(relOptSchema, rowType, entry, null);
            }
            namespace = new TableNamespace(validator, table2);
            resolved.found(namespace, false, this, path, remainingNames);
            return;
        }
        // neither sub-schema nor table
        if (namespace != null && !remainingNames.equals(names)) {
            resolved.found(namespace, false, this, path, remainingNames);
        }
        return;
    }
}
Also used : Wrapper(org.apache.calcite.schema.Wrapper) Table(org.apache.calcite.schema.Table) RelOptSchema(org.apache.calcite.plan.RelOptSchema) RelDataType(org.apache.calcite.rel.type.RelDataType) CalciteSchema(org.apache.calcite.jdbc.CalciteSchema)

Aggregations

CalciteSchema (org.apache.calcite.jdbc.CalciteSchema)2 Table (org.apache.calcite.schema.Table)2 Wrapper (org.apache.calcite.schema.Wrapper)2 MaterializationKey (org.apache.calcite.materialize.MaterializationKey)1 RelOptSchema (org.apache.calcite.plan.RelOptSchema)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1