apache/iceberg · error · NoSuchNamespaceException
Cannot rename %s to %s. Namespace does not exist: %s
Error message
Cannot rename %s to %s. Namespace does not exist: %s
What it means
renameTableOrView() (used by renameTable and renameView) throws NoSuchNamespaceException when the destination namespace (Hive database) for the rename target does not exist in the metastore. Renames can only target an existing database.
Source
Thrown at hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java:401
clients.run(
client -> client.listTableNamesByFilter(database, filter, (short) -1 /* no limit */));
return icebergTableNames.stream()
.map(tableName -> TableIdentifier.of(namespace, tableName))
.collect(Collectors.toList());
}
@SuppressWarnings("checkstyle:CyclomaticComplexity")
private void renameTableOrView(
TableIdentifier from,
TableIdentifier originalTo,
HiveOperationsBase.ContentType contentType) {
Preconditions.checkArgument(isValidIdentifier(from), "Invalid identifier: %s", from);
TableIdentifier to = removeCatalogName(originalTo);
Preconditions.checkArgument(isValidIdentifier(to), "Invalid identifier: %s", to);
if (!namespaceExists(to.namespace())) {
throw new NoSuchNamespaceException(
"Cannot rename %s to %s. Namespace does not exist: %s", from, to, to.namespace());
}
if (tableExists(to)) {
throw new AlreadyExistsException("Cannot rename %s to %s. Table already exists", from, to);
}
if (viewExists(to)) {
throw new AlreadyExistsException("Cannot rename %s to %s. View already exists", from, to);
}
String toDatabase = to.namespace().level(0);
String fromDatabase = from.namespace().level(0);
String fromName = from.name();
try {
Table table = clients.run(client -> client.getTable(fromDatabase, fromName));
validateTableIsIcebergTableOrView(contentType, table, CatalogUtil.fullTableName(name, from));View on GitHub (pinned to 86d9c8fc54)
Solutions
- Verify the destination namespace exists with catalog.namespaceExists(to.namespace()).
- Create the destination database first (CREATE DATABASE / createNamespace) if intended.
- Fix typos in the target identifier.
- Confirm the catalog's metastore URI points at the expected environment.
Example fix
// before
catalog.renameTable(oldId, TableIdentifier.of("analyticss", "events"));
// after
TableIdentifier to = TableIdentifier.of("analytics", "events");
if (!catalog.namespaceExists(to.namespace())) {
catalog.createNamespace(to.namespace());
}
catalog.renameTable(oldId, to); Defensive patterns
Strategy: validation
Validate before calling
TableIdentifier to = TableIdentifier.of("analytics", "events");
if (!catalog.namespaceExists(to.namespace())) {
throw new IllegalArgumentException("Destination namespace missing: " + to.namespace());
}
catalog.renameTable(from, to); Try / catch
try {
catalog.renameTable(from, to);
} catch (NoSuchNamespaceException e) {
// create namespace or fix identifier, then retry
throw e;
} Prevention
- Validate destination namespace with namespaceExists before every rename.
- Create destination databases as part of deployment/setup, not at rename time.
- Centralize identifier construction to prevent typos and level mistakes.
When it happens
Trigger: Calling catalog.renameTable(from, to) or catalog.renameView(from, to) where to.namespace() has no corresponding Hive database (typo, dropped database, wrong environment).
Common situations: Typo in destination database name; destination database dropped concurrently; catalog pointing at a different metastore environment; multi-level namespace not matching Hive's database naming.
Related errors
- Cannot rename %s to %s because namespace %s does not exist
- Cannot rename %s to %s. Table does not exist
- Cannot rename %s to %s. View does not exist
- Namespace already exists: %s
- Cannot rename table %s to %s: %s does not exist
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/e113f8448548a33f.
Report an issue: GitHub.