apache/iceberg · error · NoSuchNamespaceException
Cannot create table as the namespace does not exist
Error message
Cannot create table %s as the namespace does not exist
What it means
Wraps Spark's NoSuchNamespaceException raised during stageCreate when staging the destination Iceberg table: the target namespace in the destination catalog does not exist. Iceberg actions do not auto-create namespaces.
Solutions
- Create the destination namespace first: CREATE NAMESPACE <ns> in the destination catalog
- Check the destination identifier spelling and the dest catalog config (spark.sql.catalog.<name>)
- Run the action again after the namespace exists
Example fix
// before
spark.sql("CREATE TABLE iceberg_db.migrated_tbl ..."); // namespace missing
// after
spark.sql("CREATE NAMESPACE IF NOT EXISTS iceberg_db");
SparkActions.get(spark).migrateTable("db.tbl").as("iceberg_db.migrated_tbl").execute(); Defensive patterns
Strategy: validation
Validate before calling
Namespace ns = Namespace.of(parts);
if (!destCatalog.namespaceExists(ns)) { spark.sql("CREATE NAMESPACE IF NOT EXISTS " + nsString); } Try / catch
try { action.execute(); } catch (NoSuchNamespaceException e) { createNamespace(); } Prevention
- Create destination namespaces ahead of time
- Validate identifier spelling
- Pre-provision namespaces in new catalogs
When it happens
Trigger: Calling migrateTable/snapshotTable with a destination identifier whose namespace has not been created in the destination catalog, so destCatalog().stageCreate(...) throws NoSuchNamespaceException.
Common situations: Typo in the destination namespace; forgetting to CREATE NAMESPACE in the target catalog; pointing at a fresh catalog (e.g. REST/Hadoop) that has no pre-created namespaces.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Cannot apply unknown namespace change
- Cannot apply unknown namespace change
- Cannot apply unknown namespace change
- Cannot apply unknown namespace change
- Cannot create table as it already exists
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/5df0861cd011dad5.
Report an issue: GitHub.
Appendix: source
Thrown at spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/actions/BaseTableCreationSparkAction.java:164
"Cannot create Iceberg table in non-Iceberg Catalog. "
+ "Catalog '%s' was of class '%s' but '%s' or '%s' are required",
catalog.name(),
catalog.getClass().getName(),
SparkSessionCatalog.class.getName(),
SparkCatalog.class.getName());
return (StagingTableCatalog) catalog;
}
protected StagedSparkTable stageDestTable() {
try {
Map<String, String> props = destTableProps();
StructType schema = sourceTable.schema();
Transform[] partitioning = sourceTable.partitioning();
return (StagedSparkTable)
destCatalog().stageCreate(destTableIdent(), schema, partitioning, props);
} catch (org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException e) {
throw new NoSuchNamespaceException(
"Cannot create table %s as the namespace does not exist", destTableIdent());
} catch (org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException e) {
throw new AlreadyExistsException(
"Cannot create table %s as it already exists", destTableIdent());
}
}
protected void ensureNameMappingPresent(Table table) {
if (!table.properties().containsKey(TableProperties.DEFAULT_NAME_MAPPING)) {
NameMapping nameMapping = MappingUtil.create(table.schema());
String nameMappingJson = NameMappingParser.toJson(nameMapping);
table.updateProperties().set(TableProperties.DEFAULT_NAME_MAPPING, nameMappingJson).commit();
}
}
protected String getMetadataLocation(Table table) {
String defaultValue =
LocationUtil.stripTrailingSlash(table.location()) + "/" + ICEBERG_METADATA_FOLDER;View on GitHub (pinned to 86d9c8fc54)