in baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsDdlExecutor.java [297:353]
public void execute(SqlDropObject drop,
CalcitePrepare.Context context) {
final SchemaInfo schemaInfo =
schema(context, false, drop.name);
final @Nullable CalciteSchema schema =
schemaInfo.schema(); // null if schema does not exist
final String objectName = schemaInfo.name();
boolean existed;
switch (drop.getKind()) {
case DROP_TABLE:
case DROP_MATERIALIZED_VIEW:
Table materializedView =
schema != null
&& drop.getKind() == SqlKind.DROP_MATERIALIZED_VIEW
? schema.plus().getTable(objectName)
: null;
existed = schema != null && schema.removeTable(objectName);
if (existed) {
if (materializedView instanceof Wrapper) {
((Wrapper) materializedView).maybeUnwrap(MaterializationKey.class)
.ifPresent(materializationKey -> MaterializationService.instance()
.removeMaterialization(materializationKey));
}
} else if (!drop.ifExists) {
throw SqlUtil.newContextException(drop.name.getParserPosition(),
RESOURCE.tableNotFound(objectName));
}
break;
case DROP_VIEW:
// Not quite right: removes any other functions with the same name
existed = schema != null && schema.removeFunction(objectName);
if (!existed && !drop.ifExists) {
throw SqlUtil.newContextException(drop.name.getParserPosition(),
RESOURCE.viewNotFound(objectName));
}
break;
case DROP_TYPE:
existed = schema != null && schema.removeType(objectName);
if (!existed && !drop.ifExists) {
throw SqlUtil.newContextException(drop.name.getParserPosition(),
RESOURCE.typeNotFound(objectName));
}
break;
case DROP_FUNCTION:
existed = schema != null && schema.removeFunction(objectName);
if (!existed && !drop.ifExists) {
throw SqlUtil.newContextException(drop.name.getParserPosition(),
RESOURCE.functionNotFound(objectName));
}
break;
case OTHER_DDL:
default:
throw new AssertionError(drop.getKind());
}
}