{"record":{"id":"cc7da4583bd3ab41","repo":"apache/iceberg","slug":"namespace-not-found-namespace","errorCode":null,"errorMessage":"Namespace not found: ${namespace}","messagePattern":"Namespace not found: (.+?)","errorType":"exception","errorClass":"NoSuchNamespaceException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java","lineNumber":482,"sourceCode":"  public String[][] listNamespaces() {\n    if (asNamespaceCatalog != null) {\n      return asNamespaceCatalog.listNamespaces().stream()\n          .map(Namespace::levels)\n          .toArray(String[][]::new);\n    }\n\n    return new String[0][];\n  }\n\n  @Override\n  public String[][] listNamespaces(String[] namespace) throws NoSuchNamespaceException {\n    if (asNamespaceCatalog != null) {\n      try {\n        return asNamespaceCatalog.listNamespaces(Namespace.of(namespace)).stream()\n            .map(Namespace::levels)\n            .toArray(String[][]::new);\n      } catch (org.apache.iceberg.exceptions.NoSuchNamespaceException e) {\n        throw new NoSuchNamespaceException(namespace);\n      }\n    }\n\n    throw new NoSuchNamespaceException(namespace);\n  }\n\n  @Override\n  public boolean namespaceExists(String[] namespace) {\n    return asNamespaceCatalog != null\n        && asNamespaceCatalog.namespaceExists(Namespace.of(namespace));\n  }\n\n  @Override\n  public Map<String, String> loadNamespaceMetadata(String[] namespace)\n      throws NoSuchNamespaceException {\n    if (asNamespaceCatalog != null) {\n      try {\n        return asNamespaceCatalog.loadNamespaceMetadata(Namespace.of(namespace));","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java#L464-L500","documentation":"Thrown by SparkCatalog.listNamespaces(namespace) when the configured Iceberg catalog implements SupportsNamespaces but reports that the given parent namespace does not exist. Spark translates the Iceberg NoSuchNamespaceException into Spark's NoSuchNamespaceException.","triggerScenarios":"Calling 'SHOW NAMESPACES IN <ns>' or listNamespaces(ns) where ns (or a parent level of it) does not exist in the catalog; typo in a multi-level namespace; the namespace was dropped by another process.","commonSituations":"Browsing sub-namespaces of a non-existent parent, typos like 'prodc' vs 'prod', connecting to a warehouse/database where the namespace was never created, cascading drops by another job.","solutions":["Check namespaceExists(namespace) before listing its children","List top-level namespaces (listNamespaces() with no args) to see what actually exists","Correct the namespace spelling/qualifier in the query","Create the namespace first with 'CREATE NAMESPACE <ns>'"],"exampleFix":"// before\nspark.sql(\"SHOW NAMESPACES IN prod.billing\")\n// after\nif (sparkCatalog.namespaceExists(new String[]{\"prod\", \"billing\"})) {\n  spark.sql(\"SHOW NAMESPACES IN prod.billing\");\n} else {\n  spark.sql(\"CREATE NAMESPACE prod.billing\");\n  spark.sql(\"SHOW NAMESPACES IN prod.billing\");\n}","handlingStrategy":"try-catch","validationCode":"SupportsNamespaces nsc = (SupportsNamespaces) catalog;\nif (!nsc.namespaceExists(namespace)) {\n  throw new IllegalArgumentException(\"Namespace does not exist: \" + String.join(\".\", namespace));\n}","typeGuard":"boolean isListable(SupportsNamespaces catalog, String[] ns) {\n  return catalog.namespaceExists(ns);\n}","tryCatchPattern":"try {\n  catalog.listNamespaces(ns);\n} catch (org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException e) {\n  log.warn(\"Namespace {} not found; listing top-level instead\", ns, e);\n  String[][] fallback = catalog.listNamespaces();\n}","preventionTips":["Call namespaceExists before listing children","List top-level namespaces first to discover valid names","Watch for typos and level count in multi-level namespaces","Verify catalog warehouse/type config points at the right environment"],"tags":["spark","catalog","namespace","not-found"],"backgroundTag":"directory-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"}