{"record":{"id":"e657ed183ad3c71d","repo":"apache/iceberg","slug":"namespace-does-not-exist-currentnamespace","errorCode":null,"errorMessage":"Namespace does not exist: currentNamespace","messagePattern":"Namespace does not exist: currentNamespace","errorType":"exception","errorClass":"NoSuchNamespaceException","httpStatus":404,"severity":"error","filePath":"spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java","lineNumber":639,"sourceCode":"        Map<String, String> props =\n            ImmutableMap.<String, String>builder()\n                .putAll(Spark3Util.rebuildCreateProperties(properties))\n                .put(SparkView.QUERY_COLUMN_NAMES, COMMA_JOINER.join(queryColumnNames))\n                .buildKeepingLast();\n\n        org.apache.iceberg.view.View view =\n            asViewCatalog\n                .buildView(buildIdentifier(ident))\n                .withDefaultCatalog(currentCatalog)\n                .withDefaultNamespace(Namespace.of(currentNamespace))\n                .withQuery(\"spark\", sql)\n                .withSchema(icebergSchema)\n                .withLocation(properties.get(\"location\"))\n                .withProperties(props)\n                .create();\n        return new SparkView(catalogName, view);\n      } catch (org.apache.iceberg.exceptions.NoSuchNamespaceException e) {\n        throw new NoSuchNamespaceException(currentNamespace);\n      } catch (AlreadyExistsException e) {\n        throw new ViewAlreadyExistsException(ident);\n      }\n    }\n\n    throw new UnsupportedOperationException(\n        \"Creating a view is not supported by catalog: \" + catalogName);\n  }\n\n  @Override\n  public View replaceView(\n      Identifier ident,\n      String sql,\n      String currentCatalog,\n      String[] currentNamespace,\n      StructType schema,\n      String[] queryColumnNames,\n      String[] columnAliases,","sourceCodeStart":621,"sourceCodeEnd":657,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java#L621-L657","documentation":"SparkCatalog.createView throws NoSuchNamespaceException when the parent namespace of the view to create does not exist in the underlying catalog. The catalog's buildView(...).create() rejects the missing parent namespace, and SparkCatalog rethrows it using the `currentNamespace` passed by Spark. The view is not created.","triggerScenarios":"Calling CREATE VIEW <catalog>.<missing_ns>.<name> ... (which routes to createView at SparkCatalog.java:606) when the namespace `missing_ns` has not been created in the Iceberg catalog; also occurs when the underlying catalog enforces namespace existence and the session's `USE <catalog>.<namespace>` referenced a namespace absent from the Iceberg catalog.","commonSituations":"Developers forget CREATE NAMESPACE before creating a view (Iceberg catalogs do not auto-create namespaces unlike some Hive behavior); REST or JDBC catalogs configured with strict namespace validation; a typo in the namespace segment; Spark session default namespace pointing to one that was never created in the Iceberg catalog.","solutions":["Create the namespace first: CREATE NAMESPACE <catalog>.<namespace> (or catalog.createNamespace(...)).","Check the namespace spelling against SHOW NAMESPACES IN <catalog>.","If using a catalog that cannot create namespaces via Spark, create it through the catalog's admin API/client.","Confirm the current session namespace (USE <catalog>.<ns>) matches one that exists in the Iceberg catalog."],"exampleFix":"-- before\nCREATE VIEW analytics.daily_metrics AS SELECT ...;   -- namespace 'analytics' missing\n\n-- after\nCREATE NAMESPACE IF NOT EXISTS analytics;\nCREATE VIEW analytics.daily_metrics AS SELECT ...;","handlingStrategy":"validation","validationCode":"Namespace ns = Namespace.of(\"analytics\");\nif (!catalog.namespaceExists(ns)) {\n  catalog.createNamespace(ns);\n}","typeGuard":null,"tryCatchPattern":"try {\n  spark.sql(\"CREATE VIEW \" + ident + \" AS \" + sqlText);\n} catch (NoSuchNamespaceException e) {\n  spark.sql(\"CREATE NAMESPACE IF NOT EXISTS \" + parentNs);\n  spark.sql(\"CREATE VIEW \" + ident + \" AS \" + sqlText);\n}","preventionTips":["Always CREATE NAMESPACE IF NOT EXISTS as a prerequisite step in provisioning scripts.","Check SHOW NAMESPACES IN <catalog> when a namespace error appears.","Never assume implicit namespace creation — Iceberg catalogs do not auto-create parents.","Align the Spark session default namespace (USE) with namespaces that exist in the Iceberg catalog."],"tags":["spark","view-catalog","namespace"],"backgroundTag":"entity-not-found","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}