{"record":{"id":"e0feb8f49e0f5c12","repo":"prestodb/presto","slug":"schema-not-empty-e0feb8","errorCode":"SCHEMA_NOT_EMPTY","errorMessage":"Schema not empty: ","messagePattern":"Schema not empty: ","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergNativeMetadata.java","lineNumber":259,"sourceCode":"\n    @Override\n    public void createSchema(ConnectorSession session, String schemaName, Map<String, Object> properties)\n    {\n        shouldRunInAutoCommitTransaction(\"CREATE SCHEMA\");\n        catalogFactory.getNamespaces(session).createNamespace(toIcebergNamespace(Optional.of(schemaName), catalogFactory.isNestedNamespaceEnabled()),\n                properties.entrySet().stream()\n                        .collect(toMap(Map.Entry::getKey, e -> e.getValue().toString())));\n    }\n\n    @Override\n    public void dropSchema(ConnectorSession session, String schemaName)\n    {\n        shouldRunInAutoCommitTransaction(\"DROP SCHEMA\");\n        try {\n            catalogFactory.getNamespaces(session).dropNamespace(toIcebergNamespace(Optional.of(schemaName), catalogFactory.isNestedNamespaceEnabled()));\n        }\n        catch (NamespaceNotEmptyException e) {\n            throw new PrestoException(SCHEMA_NOT_EMPTY, \"Schema not empty: \" + schemaName);\n        }\n    }\n\n    @Override\n    public void renameSchema(ConnectorSession session, String source, String target)\n    {\n        shouldRunInAutoCommitTransaction(\"RENAME SCHEMA\");\n        throw new PrestoException(NOT_SUPPORTED, format(\"Iceberg %s catalog does not support rename namespace\", catalogType.name()));\n    }\n\n    @Override\n    public void createView(ConnectorSession session, ConnectorTableMetadata viewMetadata, String viewData, boolean replace)\n    {\n        shouldRunInAutoCommitTransaction(\"CREATE VIEW\");\n        validateViewDefinitionForBranches(viewData, \"CREATE VIEW\");\n        Catalog catalog = catalogFactory.getCatalog(session);\n        if (!(catalog instanceof ViewCatalog)) {\n            throw new PrestoException(NOT_SUPPORTED, \"This connector does not support creating views\");","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergNativeMetadata.java#L241-L277","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run DROP SCHEMA schema_name CASCADE after ensuring all tables can be dropped.","Explicitly list and drop all remaining tables/views: SHOW TABLES IN schema, then DROP TABLE each.","Check the catalog backend directly for orphaned table metadata and clean it up.","Verify permissions allow dropping all objects in the namespace."],"exampleFix":"// before\nDROP SCHEMA my_schema;\n// after\nDROP SCHEMA my_schema CASCADE;","handlingStrategy":"validation","validationCode":"-- before DROP SCHEMA, verify it is empty\nSELECT count(*) FROM system.jdbc.tables WHERE table_schem = 'my_schema';\n-- or in Presto:\nSHOW TABLES IN my_schema; -- must return zero rows before DROP SCHEMA","typeGuard":"boolean isSchemaEmpty(ConnectorSession session, ConnectorMetadata metadata, String schemaName) {\n    return metadata.listTables(session, schemaName).isEmpty();\n}","tryCatchPattern":"try {\n    metadata.dropSchema(session, schemaName);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getCode() == StandardErrorCode.SCHEMA_NOT_EMPTY.getCode()) {\n        // list remaining tables, drop them, then retry dropSchema\n    } else throw e;\n}","preventionTips":["Always list tables in the schema and drop them before DROP SCHEMA.","Use DROP SCHEMA ... CASCADE when intentional, and ensure the catalog honors cascade cleanup.","Check the catalog backend for orphaned table metadata not shown via SHOW TABLES.","Verify permissions cover dropping every object in the namespace."],"tags":["presto","iceberg","schema","drop","not-empty"],"backgroundTag":"schema-not-empty","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}