{"record":{"id":"08bd3e1ef1657853","repo":"apache/iceberg","slug":"databasenotemptyexception","errorCode":null,"errorMessage":"DatabaseNotEmptyException","messagePattern":"DatabaseNotEmptyException","errorType":"exception","errorClass":"DatabaseNotEmptyException","httpStatus":null,"severity":"error","filePath":"flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkCatalog.java","lineNumber":263,"sourceCode":"    }\n    return ret;\n  }\n\n  @Override\n  public void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade)\n      throws DatabaseNotExistException, DatabaseNotEmptyException, CatalogException {\n    if (asNamespaceCatalog != null) {\n      try {\n        boolean success = asNamespaceCatalog.dropNamespace(appendLevel(baseNamespace, name));\n        if (!success && !ignoreIfNotExists) {\n          throw new DatabaseNotExistException(getName(), name);\n        }\n      } catch (NoSuchNamespaceException e) {\n        if (!ignoreIfNotExists) {\n          throw new DatabaseNotExistException(getName(), name, e);\n        }\n      } catch (NamespaceNotEmptyException e) {\n        throw new DatabaseNotEmptyException(getName(), name, e);\n      }\n    } else {\n      if (!ignoreIfNotExists) {\n        throw new DatabaseNotExistException(getName(), name);\n      }\n    }\n  }\n\n  @Override\n  public void alterDatabase(String name, CatalogDatabase newDatabase, boolean ignoreIfNotExists)\n      throws DatabaseNotExistException, CatalogException {\n    if (asNamespaceCatalog != null) {\n      Namespace namespace = appendLevel(baseNamespace, name);\n      Map<String, String> updates = Maps.newHashMap();\n      Set<String> removals = Sets.newHashSet();\n\n      try {\n        Map<String, String> oldProperties = asNamespaceCatalog.loadNamespaceMetadata(namespace);","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkCatalog.java#L245-L281","documentation":"FlinkCatalog.dropDatabase throws DatabaseNotEmptyException when the underlying Iceberg catalog raises NamespaceNotEmptyException, i.e. the namespace still contains tables (or views) and cannot be dropped while cascade=false. The namespace is NOT removed and its contents remain intact.","triggerScenarios":"Calling dropDatabase(name, ignoreIfNotExists=false, cascade=false) — e.g. DROP DATABASE without CASCADE — on a namespace that still holds tables/views in the Iceberg catalog.","commonSituations":"Attempting to clean up a database that still has Iceberg tables; forgetting CASCADE in Flink SQL; assuming drop of the namespace recursively deletes contents when the wrapped catalog refuses.","solutions":["Drop or purge all tables in the database first (DROP TABLE each, or purge)","Use DROP DATABASE ... CASCADE so the call passes cascade semantics (FlinkCatalog translates this so the Iceberg dropNamespace purge succeeds)","Check listTables(database) to see what remains blocking the drop","If tables are stale/orphaned, remove them via the Iceberg catalog directly before retrying"],"exampleFix":"// before\nstaging.executeSql(\"DROP DATABASE my_db\");\n// after\nstaging.executeSql(\"DROP DATABASE my_db CASCADE\");","handlingStrategy":"validation","validationCode":"boolean empty = catalog.listTables(dbName).isEmpty();\nif (!empty) throw new IllegalStateException(\"Database \" + dbName + \" still contains tables\");","typeGuard":null,"tryCatchPattern":"try {\n  catalog.dropDatabase(name, false, false);\n} catch (DatabaseNotEmptyException e) {\n  catalog.listTables(name).forEach(t -> catalog.dropTable(ObjectPath.fromString(name + \".\" + t), true));\n  catalog.dropDatabase(name, false, true);\n}","preventionTips":["List tables before dropping a database","Use CASCADE explicitly when recursive deletion is intended","Never assume namespace drop is recursive in Iceberg"],"tags":["flink","iceberg","catalog","namespace-not-empty"],"backgroundTag":"invalid-state-transition","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}