{"record":{"id":"94629ef949f40e72","repo":"apache/iceberg","slug":"cannot-rename-s-to-s-because-namespace-s-does-n","errorCode":null,"errorMessage":"Cannot rename %s to %s because namespace %s does not exist","messagePattern":"Cannot rename (.+?) to (.+?) because namespace (.+?) does not exist","errorType":"exception","errorClass":"NoSuchNamespaceException","httpStatus":null,"severity":"error","filePath":"aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java","lineNumber":402,"sourceCode":"      return false;\n    } catch (Exception e) {\n      LOG.error(\n          \"Cannot complete drop table operation for {} due to unexpected exception\", identifier, e);\n      throw e;\n    }\n  }\n\n  /**\n   * Rename table in Glue is a drop table and create table.\n   *\n   * @param from identifier of the table to rename\n   * @param to new table name\n   */\n  @Override\n  public void renameTable(TableIdentifier from, TableIdentifier to) {\n    // check new namespace exists\n    if (!namespaceExists(to.namespace())) {\n      throw new NoSuchNamespaceException(\n          \"Cannot rename %s to %s because namespace %s does not exist\", from, to, to.namespace());\n    }\n    // keep metadata\n    Table fromTable;\n    String fromTableDbName =\n        IcebergToGlueConverter.getDatabaseName(from, awsProperties.glueCatalogSkipNameValidation());\n    String fromTableName =\n        IcebergToGlueConverter.getTableName(from, awsProperties.glueCatalogSkipNameValidation());\n    String toTableDbName =\n        IcebergToGlueConverter.getDatabaseName(to, awsProperties.glueCatalogSkipNameValidation());\n    String toTableName =\n        IcebergToGlueConverter.getTableName(to, awsProperties.glueCatalogSkipNameValidation());\n    try {\n      GetTableResponse response =\n          glue.getTable(\n              GetTableRequest.builder()\n                  .catalogId(awsProperties.glueCatalogId())\n                  .databaseName(fromTableDbName)","sourceCodeStart":384,"sourceCodeEnd":420,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java#L384-L420","documentation":"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.","triggerScenarios":"ALTER TABLE ... RENAME TO (Spark) or catalog.renameTable(from, to) where to.namespace() refers to a Glue database that does not exist.","commonSituations":"Typo in target database name; target database dropped before rename; cross-database move where only the source database exists.","solutions":["Create the target namespace/database first: catalog.createNamespace(to.namespace()) or CREATE DATABASE in Glue/Spark","Fix the typo in the target namespace name","Verify the Glue database exists in the same region/catalog id configured for the GlueCatalog"],"exampleFix":"// before\nspark.sql(\"ALTER TABLE db1.t RENAME TO db2.t\"); // db2 missing\n// after\nspark.sql(\"CREATE DATABASE IF NOT EXISTS db2\");\nspark.sql(\"ALTER TABLE db1.t RENAME TO db2.t\");","handlingStrategy":"validation","validationCode":"if (!catalog.namespaceExists(to.namespace())) {\n  catalog.createNamespace(to.namespace());\n}\ncatalog.renameTable(from, to);","typeGuard":null,"tryCatchPattern":"try {\n  catalog.renameTable(from, to);\n} catch (NoSuchNamespaceException e) {\n  catalog.createNamespace(to.namespace());\n  catalog.renameTable(from, to);\n}","preventionTips":["CREATE DATABASE IF NOT EXISTS before cross-database renames","Validate target namespace names before issuing RENAME","Keep database inventories consistent across environments"],"tags":["aws","glue","rename","namespace-not-found"],"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-23T08:17:48.524Z"}