{"record":{"id":"6eccfe4e3cb1ff41","repo":"apache/iceberg","slug":"glue-does-not-support-nested-namespace-cannot-lis","errorCode":null,"errorMessage":"Glue does not support nested namespace, cannot list namespaces under %s","messagePattern":"Glue does not support nested namespace, cannot list namespaces under (.+?)","errorType":"exception","errorClass":"NoSuchNamespaceException","httpStatus":null,"severity":"error","filePath":"aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java","lineNumber":490,"sourceCode":"              .databaseInput(\n                  IcebergToGlueConverter.toDatabaseInput(\n                      namespace, metadata, awsProperties.glueCatalogSkipNameValidation()))\n              .build());\n      LOG.info(\"Created namespace: {}\", namespace);\n    } catch (software.amazon.awssdk.services.glue.model.AlreadyExistsException e) {\n      throw new AlreadyExistsException(\n          \"Cannot create namespace %s because it already exists in Glue\", namespace);\n    }\n  }\n\n  @Override\n  public List<Namespace> listNamespaces(Namespace namespace) throws NoSuchNamespaceException {\n    if (!namespace.isEmpty()) {\n      // if it is not a list all op, just check if the namespace exists and return empty.\n      if (namespaceExists(namespace)) {\n        return Lists.newArrayList();\n      }\n      throw new NoSuchNamespaceException(\n          \"Glue does not support nested namespace, cannot list namespaces under %s\", namespace);\n    }\n\n    // should be safe to list all before returning the list, instead of dynamically load the list.\n    String nextToken = null;\n    List<Namespace> results = Lists.newArrayList();\n    do {\n      GetDatabasesResponse response =\n          glue.getDatabases(\n              GetDatabasesRequest.builder()\n                  .catalogId(awsProperties.glueCatalogId())\n                  .nextToken(nextToken)\n                  .build());\n      nextToken = response.nextToken();\n      if (response.hasDatabaseList()) {\n        results.addAll(\n            response.databaseList().stream()\n                .map(GlueToIcebergConverter::toNamespace)","sourceCodeStart":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java#L472-L508","documentation":"GlueCatalog.listNamespaces throws NoSuchNamespaceException when asked to list sub-namespaces under a non-empty namespace. Glue databases are flat — there is no hierarchy — so any listing of a nested level is invalid, and if the given (single-level) namespace itself doesn't exist the call fails.","triggerScenarios":"Calling catalog.listNamespaces(Namespace.of(\"a\",\"b\")) (a multi-level namespace) — Glue can never have nested namespaces; or calling it with a one-level namespace that does not exist as a Glue database.","commonSituations":"Generic catalog exploration code that recursively lists namespaces (works on Hadoop/Hive catalogs but not Glue); assuming SQL-style `db.schema.table` three-part names; migrating code from another catalog implementation without adapting namespace handling.","solutions":["Call listNamespaces with an empty namespace to list all top-level Glue databases, and never recurse into sub-namespaces with Glue.","Verify the namespace you pass is a single-level name that exists (`namespaceExists`) before listing under it.","Refactor code that assumes hierarchical namespaces to use flat names (e.g. underscores) when targeting Glue."],"exampleFix":"// before\nfor (Namespace child : catalog.listNamespaces(ns)) { ... } // recursive listing\n\n// after\nif (ns.isEmpty()) {\n  List<Namespace> all = catalog.listNamespaces(); // top-level only\n}\n// Glue namespaces are flat: do not list under a non-empty namespace","handlingStrategy":"validation","validationCode":"if (!ns.isEmpty()) {\n  // Glue is flat: never list sub-namespaces\n  if (!catalog.namespaceExists(ns)) {\n    throw new IllegalArgumentException(\"Namespace \" + ns + \" does not exist in Glue\");\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  return catalog.listNamespaces(ns);\n} catch (NoSuchNamespaceException e) {\n  LOG.warn(\"Glue is flat, cannot list under {}: {}\", ns, e.getMessage());\n  return List.of();\n}","preventionTips":["Never recurse into sub-namespaces with GlueCatalog — only call listNamespaces() with an empty namespace","Flatten hierarchical names (db_schema) when migrating from Hive/Hadoop catalogs","Check namespaceExists before listing under a specific namespace"],"tags":["aws","glue","namespace","unsupported","hierarchy"],"backgroundTag":"unsupported-operation","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"}