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);
}
}
}
}
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;
}
}
Aggregations