Skip to content

Commit

Permalink
Check table and view existence in Memory connector
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Mar 15, 2022
1 parent 39607b5 commit d8e111c
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static io.trino.spi.StandardErrorCode.ALREADY_EXISTS;
import static io.trino.spi.StandardErrorCode.NOT_FOUND;
import static io.trino.spi.StandardErrorCode.SCHEMA_NOT_EMPTY;
import static io.trino.spi.connector.RetryMode.NO_RETRIES;
import static io.trino.spi.connector.SampleType.SYSTEM;
import static java.lang.String.format;
Expand Down Expand Up @@ -115,9 +116,29 @@ public synchronized void dropSchema(ConnectorSession session, String schemaName)
throw new TrinoException(NOT_FOUND, format("Schema [%s] does not exist", schemaName));
}

// DropSchemaTask has the same logic, but needs to check in connector side considering concurrent operations
if (!isSchemaEmpty(schemaName)) {
throw new TrinoException(SCHEMA_NOT_EMPTY, "Schema not empty: " + schemaName);
}

verify(schemas.remove(schemaName));
}

private boolean isSchemaEmpty(String schemaName)
{
if (tables.values().stream()
.anyMatch(table -> table.getSchemaName().equals(schemaName))) {
return false;
}

if (views.keySet().stream()
.anyMatch(view -> view.getSchemaName().equals(schemaName))) {
return false;
}

return true;
}

@Override
public synchronized ConnectorTableHandle getTableHandle(ConnectorSession session, SchemaTableName schemaTableName)
{
Expand Down

0 comments on commit d8e111c

Please sign in to comment.