{"record":{"id":"e113f8448548a33f","repo":"apache/iceberg","slug":"cannot-rename-s-to-s-namespace-does-not-exist-e113f8","errorCode":null,"errorMessage":"Cannot rename %s to %s. Namespace does not exist: %s","messagePattern":"Cannot rename (.+?) to (.+?)\\. Namespace does not exist: (.+?)","errorType":"exception","errorClass":"NoSuchNamespaceException","httpStatus":404,"severity":"error","filePath":"hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java","lineNumber":401,"sourceCode":"        clients.run(\n            client -> client.listTableNamesByFilter(database, filter, (short) -1 /* no limit */));\n\n    return icebergTableNames.stream()\n        .map(tableName -> TableIdentifier.of(namespace, tableName))\n        .collect(Collectors.toList());\n  }\n\n  @SuppressWarnings(\"checkstyle:CyclomaticComplexity\")\n  private void renameTableOrView(\n      TableIdentifier from,\n      TableIdentifier originalTo,\n      HiveOperationsBase.ContentType contentType) {\n    Preconditions.checkArgument(isValidIdentifier(from), \"Invalid identifier: %s\", from);\n\n    TableIdentifier to = removeCatalogName(originalTo);\n    Preconditions.checkArgument(isValidIdentifier(to), \"Invalid identifier: %s\", to);\n    if (!namespaceExists(to.namespace())) {\n      throw new NoSuchNamespaceException(\n          \"Cannot rename %s to %s. Namespace does not exist: %s\", from, to, to.namespace());\n    }\n\n    if (tableExists(to)) {\n      throw new AlreadyExistsException(\"Cannot rename %s to %s. Table already exists\", from, to);\n    }\n\n    if (viewExists(to)) {\n      throw new AlreadyExistsException(\"Cannot rename %s to %s. View already exists\", from, to);\n    }\n\n    String toDatabase = to.namespace().level(0);\n    String fromDatabase = from.namespace().level(0);\n    String fromName = from.name();\n\n    try {\n      Table table = clients.run(client -> client.getTable(fromDatabase, fromName));\n      validateTableIsIcebergTableOrView(contentType, table, CatalogUtil.fullTableName(name, from));","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java#L383-L419","documentation":"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.","triggerScenarios":"Calling catalog.renameTable(from, to) or catalog.renameView(from, to) where to.namespace() has no corresponding Hive database (typo, dropped database, wrong environment).","commonSituations":"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.","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."],"exampleFix":"// before\ncatalog.renameTable(oldId, TableIdentifier.of(\"analyticss\", \"events\"));\n// after\nTableIdentifier to = TableIdentifier.of(\"analytics\", \"events\");\nif (!catalog.namespaceExists(to.namespace())) {\n  catalog.createNamespace(to.namespace());\n}\ncatalog.renameTable(oldId, to);","handlingStrategy":"validation","validationCode":"TableIdentifier to = TableIdentifier.of(\"analytics\", \"events\");\nif (!catalog.namespaceExists(to.namespace())) {\n  throw new IllegalArgumentException(\"Destination namespace missing: \" + to.namespace());\n}\ncatalog.renameTable(from, to);","typeGuard":null,"tryCatchPattern":"try {\n  catalog.renameTable(from, to);\n} catch (NoSuchNamespaceException e) {\n  // create namespace or fix identifier, then retry\n  throw e;\n}","preventionTips":["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."],"tags":["hive-metastore","rename","namespace","catalog"],"backgroundTag":"namespace-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"}