apache/iceberg · error · NoSuchNamespaceException

Cannot rename to because namespace does not exist

Error message

Cannot rename %s to %s because namespace %s does not exist

What it means

NoSuchNamespaceException thrown by GlueCatalog.renameTable when the target namespace (Glue database) does not exist. Renaming requires the destination database to already exist so the table metadata (including location) can move under it.

Solutions

  1. Create the target namespace/database first: catalog.createNamespace(to.namespace()) or CREATE DATABASE in Glue/Spark
  2. Fix the typo in the target namespace name
  3. Verify the Glue database exists in the same region/catalog id configured for the GlueCatalog

Example fix

// before
spark.sql("ALTER TABLE db1.t RENAME TO db2.t"); // db2 missing
// after
spark.sql("CREATE DATABASE IF NOT EXISTS db2");
spark.sql("ALTER TABLE db1.t RENAME TO db2.t");
Defensive patterns

Strategy: validation

Validate before calling

if (!catalog.namespaceExists(to.namespace())) {
  catalog.createNamespace(to.namespace());
}
catalog.renameTable(from, to);

Try / catch

try {
  catalog.renameTable(from, to);
} catch (NoSuchNamespaceException e) {
  catalog.createNamespace(to.namespace());
  catalog.renameTable(from, to);
}

Prevention

When it happens

Trigger: ALTER TABLE ... RENAME TO (Spark) or catalog.renameTable(from, to) where to.namespace() refers to a Glue database that does not exist.

Common situations: Typo in target database name; target database dropped before rename; cross-database move where only the source database exists.

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


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/94629ef949f40e72. Report an issue: GitHub.

Appendix: source

Thrown at aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java:402

      return false;
    } catch (Exception e) {
      LOG.error(
          "Cannot complete drop table operation for {} due to unexpected exception", identifier, e);
      throw e;
    }
  }

  /**
   * Rename table in Glue is a drop table and create table.
   *
   * @param from identifier of the table to rename
   * @param to new table name
   */
  @Override
  public void renameTable(TableIdentifier from, TableIdentifier to) {
    // check new namespace exists
    if (!namespaceExists(to.namespace())) {
      throw new NoSuchNamespaceException(
          "Cannot rename %s to %s because namespace %s does not exist", from, to, to.namespace());
    }
    // keep metadata
    Table fromTable;
    String fromTableDbName =
        IcebergToGlueConverter.getDatabaseName(from, awsProperties.glueCatalogSkipNameValidation());
    String fromTableName =
        IcebergToGlueConverter.getTableName(from, awsProperties.glueCatalogSkipNameValidation());
    String toTableDbName =
        IcebergToGlueConverter.getDatabaseName(to, awsProperties.glueCatalogSkipNameValidation());
    String toTableName =
        IcebergToGlueConverter.getTableName(to, awsProperties.glueCatalogSkipNameValidation());
    try {
      GetTableResponse response =
          glue.getTable(
              GetTableRequest.builder()
                  .catalogId(awsProperties.glueCatalogId())
                  .databaseName(fromTableDbName)

View on GitHub (pinned to 86d9c8fc54)