prestodb/presto · error · PrestoException

SCHEMA_NOT_EMPTY

SCHEMA_NOT_EMPTY

Error message

Schema not empty: 

What it means

This error wraps Iceberg's NamespaceNotEmptyException: a DROP SCHEMA against an Iceberg native catalog failed because the namespace still contains tables (or other objects). Presto translates it into SCHEMA_NOT_EMPTY so the user knows the schema must be emptied before it can be dropped.

Source

Thrown at presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergNativeMetadata.java:259

    @Override
    public void createSchema(ConnectorSession session, String schemaName, Map<String, Object> properties)
    {
        shouldRunInAutoCommitTransaction("CREATE SCHEMA");
        catalogFactory.getNamespaces(session).createNamespace(toIcebergNamespace(Optional.of(schemaName), catalogFactory.isNestedNamespaceEnabled()),
                properties.entrySet().stream()
                        .collect(toMap(Map.Entry::getKey, e -> e.getValue().toString())));
    }

    @Override
    public void dropSchema(ConnectorSession session, String schemaName)
    {
        shouldRunInAutoCommitTransaction("DROP SCHEMA");
        try {
            catalogFactory.getNamespaces(session).dropNamespace(toIcebergNamespace(Optional.of(schemaName), catalogFactory.isNestedNamespaceEnabled()));
        }
        catch (NamespaceNotEmptyException e) {
            throw new PrestoException(SCHEMA_NOT_EMPTY, "Schema not empty: " + schemaName);
        }
    }

    @Override
    public void renameSchema(ConnectorSession session, String source, String target)
    {
        shouldRunInAutoCommitTransaction("RENAME SCHEMA");
        throw new PrestoException(NOT_SUPPORTED, format("Iceberg %s catalog does not support rename namespace", catalogType.name()));
    }

    @Override
    public void createView(ConnectorSession session, ConnectorTableMetadata viewMetadata, String viewData, boolean replace)
    {
        shouldRunInAutoCommitTransaction("CREATE VIEW");
        validateViewDefinitionForBranches(viewData, "CREATE VIEW");
        Catalog catalog = catalogFactory.getCatalog(session);
        if (!(catalog instanceof ViewCatalog)) {
            throw new PrestoException(NOT_SUPPORTED, "This connector does not support creating views");

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Run DROP SCHEMA schema_name CASCADE after ensuring all tables can be dropped.
  2. Explicitly list and drop all remaining tables/views: SHOW TABLES IN schema, then DROP TABLE each.
  3. Check the catalog backend directly for orphaned table metadata and clean it up.
  4. Verify permissions allow dropping all objects in the namespace.

Example fix

// before
DROP SCHEMA my_schema;
// after
DROP SCHEMA my_schema CASCADE;
Defensive patterns

Strategy: validation

Validate before calling

-- before DROP SCHEMA, verify it is empty
SELECT count(*) FROM system.jdbc.tables WHERE table_schem = 'my_schema';
-- or in Presto:
SHOW TABLES IN my_schema; -- must return zero rows before DROP SCHEMA

Type guard

boolean isSchemaEmpty(ConnectorSession session, ConnectorMetadata metadata, String schemaName) {
    return metadata.listTables(session, schemaName).isEmpty();
}

Try / catch

try {
    metadata.dropSchema(session, schemaName);
} catch (PrestoException e) {
    if (e.getErrorCode().getCode() == StandardErrorCode.SCHEMA_NOT_EMPTY.getCode()) {
        // list remaining tables, drop them, then retry dropSchema
    } else throw e;
}

Prevention

When it happens

Trigger: DROP SCHEMA schemaName (especially DROP SCHEMA ... CASCADE not taking effect at the catalog level) when the Iceberg namespace still contains tables, views, or materialized views; catalogFactory.getNamespaces(session).dropNamespace throws NamespaceNotEmptyException which is caught and rethrown here.

Common situations: Running DROP SCHEMA without CASCADE while tables remain; CASCADE drop partially failing (some tables dropped, some errors) leaving the namespace non-empty; orphaned table metadata in the catalog not visible in Presto listings; permission issues preventing listing/dropping of some tables.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/e0feb8f49e0f5c12. Report an issue: GitHub.