{"record":{"id":"9d9e43c843fcf1a4","repo":"apache/iceberg","slug":"databasenotexistexception","errorCode":null,"errorMessage":"DatabaseNotExistException","messagePattern":"DatabaseNotExistException","errorType":"exception","errorClass":"DatabaseNotExistException","httpStatus":null,"severity":"error","filePath":"flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkCatalog.java","lineNumber":186,"sourceCode":"  }\n\n  @Override\n  public List<String> listDatabases() throws CatalogException {\n    if (asNamespaceCatalog == null) {\n      return Collections.singletonList(getDefaultDatabase());\n    }\n\n    return asNamespaceCatalog.listNamespaces(baseNamespace).stream()\n        .map(n -> n.level(n.levels().length - 1))\n        .collect(Collectors.toList());\n  }\n\n  @Override\n  public CatalogDatabase getDatabase(String databaseName)\n      throws DatabaseNotExistException, CatalogException {\n    if (asNamespaceCatalog == null) {\n      if (!getDefaultDatabase().equals(databaseName)) {\n        throw new DatabaseNotExistException(getName(), databaseName);\n      } else {\n        return new CatalogDatabaseImpl(Maps.newHashMap(), \"\");\n      }\n    } else {\n      try {\n        Map<String, String> metadata =\n            Maps.newHashMap(\n                asNamespaceCatalog.loadNamespaceMetadata(appendLevel(baseNamespace, databaseName)));\n        String comment = metadata.remove(\"comment\");\n        return new CatalogDatabaseImpl(metadata, comment);\n      } catch (NoSuchNamespaceException e) {\n        throw new DatabaseNotExistException(getName(), databaseName, e);\n      }\n    }\n  }\n\n  @Override\n  public boolean databaseExists(String databaseName) throws CatalogException {","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkCatalog.java#L168-L204","documentation":"FlinkCatalog.getDatabase throws Flink's DatabaseNotExistException when the underlying catalog does not support namespaces (asNamespaceCatalog == null) and the requested database is not the configured default database. Flat catalogs only expose a single synthetic default database, so any other name cannot exist.","triggerScenarios":"Calling getDatabase (directly or via databaseExists/listTables paths) with a non-default database name on a catalog impl that lacks namespace support, e.g. type of catalog configured without nested-namespace capability.","commonSituations":"Flink SQL 'USE db' or 'SHOW CREATE TABLE db.tbl' against an Iceberg catalog deployed in flat mode; migration from an Hadoop/Hive catalog (namespaced) to a flat catalog while old SQL references remain.","solutions":["Use the catalog's default database name instead of an explicit namespace, or prefix nothing in SQL.","Reconfigure the catalog to a namespace-capable implementation (e.g. HadoopCatalog/JdbcCatalog/NamespaceCatalog-backed) if real databases are needed.","Check the 'catalog.type'/base-namespace configuration to confirm whether namespace support is expected.","Catch DatabaseNotExistException and fall back to the default database for legacy queries."],"exampleFix":"// before\nCatalogDatabase db = catalog.getDatabase(\"analytics\"); // flat catalog\n// after\nCatalogDatabase db = catalog.getDatabase(catalog.getDefaultDatabase());","handlingStrategy":"try-catch","validationCode":"// verify the catalog supports namespaces before addressing non-default databases\nboolean namespaced = catalog.listDatabases().size() > 1 || !catalog.getDefaultDatabase().equals(databaseName);","typeGuard":null,"tryCatchPattern":"try {\n  CatalogDatabase db = catalog.getDatabase(name);\n} catch (DatabaseNotExistException e) {\n  // fall back to default database for flat catalogs\n  db = catalog.getDatabase(catalog.getDefaultDatabase());\n}","preventionTips":["Know your catalog mode: flat catalogs expose only the default database","Migrate SQL scripts when switching from Hive/Hadoop catalogs to flat ones","Call databaseExists() before getDatabase() in probing code"],"tags":["flink","catalog","namespace"],"backgroundTag":"resource-not-found","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"}