{"record":{"id":"d036c781bb0a765b","repo":"apache/iceberg","slug":"cannot-create-table-s-as-the-namespace-does-not-e-d036c7","errorCode":null,"errorMessage":"Cannot create table %s as the namespace does not exist","messagePattern":"Cannot create table (.+?) as the namespace does not exist","errorType":"exception","errorClass":"NoSuchNamespaceException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/actions/BaseTableCreationSparkAction.java","lineNumber":164,"sourceCode":"            + \"Catalog '%s' was of class '%s' but '%s' or '%s' are required\",\n        catalog.name(),\n        catalog.getClass().getName(),\n        SparkSessionCatalog.class.getName(),\n        SparkCatalog.class.getName());\n\n    return (StagingTableCatalog) catalog;\n  }\n\n  protected StagedSparkTable stageDestTable() {\n    try {\n      Map<String, String> props = destTableProps();\n      return (StagedSparkTable)\n          destCatalog()\n              .stageCreate(\n                  destTableIdent(),\n                  Spark3Util.tableInfo(sourceTable.columns(), sourceTable.partitioning(), props));\n    } catch (org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException e) {\n      throw new NoSuchNamespaceException(\n          \"Cannot create table %s as the namespace does not exist\", destTableIdent());\n    } catch (org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException e) {\n      throw new AlreadyExistsException(\n          \"Cannot create table %s as it already exists\", destTableIdent());\n    }\n  }\n\n  protected void ensureNameMappingPresent(Table table) {\n    if (!table.properties().containsKey(TableProperties.DEFAULT_NAME_MAPPING)) {\n      NameMapping nameMapping = MappingUtil.create(table.schema());\n      String nameMappingJson = NameMappingParser.toJson(nameMapping);\n      table.updateProperties().set(TableProperties.DEFAULT_NAME_MAPPING, nameMappingJson).commit();\n    }\n  }\n\n  protected String getMetadataLocation(Table table) {\n    String defaultValue =\n        LocationUtil.stripTrailingSlash(table.location()) + \"/\" + ICEBERG_METADATA_FOLDER;","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/actions/BaseTableCreationSparkAction.java#L146-L182","documentation":"stageDestTable calls destCatalog().stageCreate; if Spark reports NoSuchNamespaceException, the action rethrows it as Iceberg NoSuchNamespaceException stating the destination namespace does not exist. The destination catalog must already contain the target namespace.","triggerScenarios":"CREATE/SNAPSHOT/ MIGRATE actions with a destination identifier in a namespace never created in the destination catalog — e.g. snapshotting into db2.backup when namespace db2.backup is absent.","commonSituations":"Typos in destination namespace; forgetting CREATE NAMESPACE before the action; pointing the destination at a catalog where the namespace hierarchy differs.","solutions":["Create the destination namespace first: CREATE NAMESPACE catalog.ns","Verify the destination identifier and catalog name are correct","List namespaces (SHOW NAMESPACES IN catalog) to confirm the target exists"],"exampleFix":"// before\nCALL cat.system.snapshot('src.tbl', 'cat.analytics.orders') // analytics missing\n// after\nCREATE NAMESPACE cat.analytics;\nCALL cat.system.snapshot('src.tbl', 'cat.analytics.orders');","handlingStrategy":"validation","validationCode":"if (!spark.catalog().databaseExists(ns)) { spark.sql(\"CREATE NAMESPACE \" + ns); }","typeGuard":"boolean namespaceExists(SparkSession spark, String ns) { return spark.catalog().databaseExists(ns); }","tryCatchPattern":"try { callAction(...); } catch (NoSuchNamespaceException e) { LOG.error(\"Dest namespace missing for {}\", destIdent, e); throw e; }","preventionTips":["CREATE NAMESPACE before create-like actions","Verify destination identifiers against SHOW NAMESPACES output","Automate namespace provisioning in job setup"],"tags":["spark","namespace-not-found","actions"],"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-14T16:17:12.679Z"}