{"record":{"id":"03d726d975028309","repo":"apache/seatunnel","slug":"database-s-not-empty-can-t-drop-it","errorCode":null,"errorMessage":"Database %s not empty, can't drop it.","messagePattern":"Database (.+?) not empty, can't drop it\\.","errorType":"exception","errorClass":"CatalogException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-hudi/src/main/java/org/apache/seatunnel/connectors/seatunnel/hudi/catalog/HudiCatalog.java","lineNumber":310,"sourceCode":"                    e);\n        }\n    }\n\n    @Override\n    public void dropDatabase(TablePath tablePath, boolean ignoreIfNotExists)\n            throws DatabaseNotExistException, CatalogException {\n        // do nothing\n        if (!databaseExists(tablePath.getDatabaseName())) {\n            if (ignoreIfNotExists) {\n                return;\n            } else {\n                throw new DatabaseNotExistException(catalogName, tablePath.getDatabaseName());\n            }\n        }\n\n        List<String> tables = listTables(tablePath.getDatabaseName());\n        if (!tables.isEmpty()) {\n            throw new CatalogException(\n                    String.format(\n                            \"Database %s not empty, can't drop it.\", tablePath.getDatabaseName()));\n        }\n\n        Path dbPath = new Path(tableParentDfsPath, tablePath.getDatabaseName());\n        try {\n            fs.delete(dbPath, true);\n        } catch (IOException e) {\n            throw new CatalogException(\n                    String.format(\"Dropping database %s exception.\", tablePath.getDatabaseName()),\n                    e);\n        }\n    }\n\n    private TableSchema convertSchema(\n            TableSchema.Builder tableSchemaBuilder, HoodieTableConfig tableConfig) {\n        if (tableConfig.getTableCreateSchema().isPresent()) {\n            Schema schema = tableConfig.getTableCreateSchema().get();","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-hudi/src/main/java/org/apache/seatunnel/connectors/seatunnel/hudi/catalog/HudiCatalog.java#L292-L328","documentation":"HudiCatalog.dropDatabase() refuses to drop a database (namespace on the DFS) that still contains tables. Before deleting the database directory it calls listTables(); if any table exists it aborts with this CatalogException to prevent silent data loss. You must drop or remove all tables in the database first.","triggerScenarios":"Calling catalog.dropDatabase(tablePath) when listTables(databaseName) returns a non-empty list, i.e. there are still Hudi tables under the database directory on the filesystem.","commonSituations":"Automation scripts dropping databases without enumerating tables first; drop cascades executed while stale/undeleted Hudi tables remain on DFS; users assuming dropDatabase is recursive like SQL DROP ... CASCADE.","solutions":["List and drop every table in the database before calling dropDatabase (e.g. for each table in catalog.listTables(db) call catalog.dropTable(tablePath)).","If the tables are not needed, manually remove the leftover directories on the underlying DFS (HDFS/S3) so listTables returns empty.","If the database is intentionally expected empty but is not, verify the warehouse/tableParentDfsPath configuration is not pointing at the wrong location."],"exampleFix":"// before\ncatalog.dropDatabase(tablePath);\n\n// after\nfor (String table : catalog.listTables(tablePath.getDatabaseName())) {\n    catalog.dropTable(TablePath.of(tablePath.getDatabaseName(), table));\n}\ncatalog.dropDatabase(tablePath);","handlingStrategy":"validation","validationCode":"if (!catalog.listTables(tablePath.getDatabaseName()).isEmpty()) {\n    throw new IllegalStateException(\"Database not empty: \" + tablePath.getDatabaseName());\n}\ncatalog.dropDatabase(tablePath);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always enumerate and drop tables before dropping a Hudi database.","Remember dropDatabase is not a cascade operation.","Verify the warehouse path before dropping to rule out stale directories."],"tags":["hudi","catalog","database-drop","precondition"],"backgroundTag":"invalid-state-transition","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}