{"record":{"id":"4f20beca96483799","repo":"apache/iceberg","slug":"namespace-not-found-currentnamespace","errorCode":null,"errorMessage":"Namespace not found: ${currentNamespace}","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":642,"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":624,"sourceCodeEnd":660,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java#L624-L660","documentation":"Thrown by SparkCatalog.createView when the underlying view catalog reports that the namespace targeted by CREATE VIEW does not exist. The Iceberg NoSuchNamespaceException is converted to a Spark NoSuchNamespaceException naming currentNamespace. The view creation itself never proceeds.","triggerScenarios":"CREATE VIEW prod.db.v AS SELECT ... where namespace prod.db was never created or was dropped before the create; programmatic catalog.createView(...) into a non-existent namespace.","commonSituations":"Skipping CREATE NAMESPACE in fresh environments or CI pipelines; namespace deleted concurrently by another job; creating views under the wrong catalog whose namespaces are separate from tables'.","solutions":["Run CREATE NAMESPACE IF NOT EXISTS <catalog.db> before CREATE VIEW","In code, call catalog.namespaceExists or createNamespace(Namespace.of(currentNamespace)) first","Verify the catalog and namespace prefix in the view identifier","Check for concurrent jobs that may have dropped the namespace"],"exampleFix":"// before\nspark.sql(\"CREATE VIEW prod.db.my_view AS SELECT 1\") // Namespace not found: [db]\n// after\nspark.sql(\"CREATE NAMESPACE IF NOT EXISTS prod.db\")\nspark.sql(\"CREATE VIEW prod.db.my_view AS SELECT 1\")","handlingStrategy":"validation","validationCode":"Namespace ns = Namespace.of(currentNamespace);\nif (!viewCatalog.namespaceExists(ns)) {\n  viewCatalog.createNamespace(ns);\n}\nviewCatalog.createView(ident, schema, spec, sortOrder, location, props, sql);","typeGuard":"boolean canCreateViewIn(ViewCatalog catalog, String[] namespace) {\n  return catalog.namespaceExists(Namespace.of(namespace));\n}","tryCatchPattern":"try {\n  spark.sql(\"CREATE VIEW \" + ident + \" AS \" + sql);\n} catch (NoSuchNamespaceException e) {\n  spark.sql(\"CREATE NAMESPACE IF NOT EXISTS \" + namespacePart(ident));\n  spark.sql(\"CREATE VIEW \" + ident + \" AS \" + sql);\n}","preventionTips":["Always bootstrap namespaces in deployment scripts before creating views","Use CREATE NAMESPACE IF NOT EXISTS for idempotency","Keep table and view namespaces in the same catalog to avoid split-brain","Run a pre-flight step in CI that creates all required namespaces"],"tags":["spark","view","namespace","create"],"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-23T08:17:48.524Z"}