{"record":{"id":"10acdb604a5d42d5","repo":"apache/iceberg","slug":"table-already-exists-s-10acdb","errorCode":null,"errorMessage":"Table already exists: %s","messagePattern":"Table already exists: (.+?)","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":409,"severity":"error","filePath":"hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java","lineNumber":443,"sourceCode":"          client -> {\n            MetastoreUtil.alterTable(client, fromDatabase, fromName, table);\n            return null;\n          });\n\n      LOG.info(\"Renamed {} from {}, to {}\", contentType.value(), from, to);\n\n    } catch (NoSuchObjectException e) {\n      switch (contentType) {\n        case TABLE:\n          throw new NoSuchTableException(\"Cannot rename %s to %s. Table does not exist\", from, to);\n        case VIEW:\n          throw new NoSuchViewException(\"Cannot rename %s to %s. View does not exist\", from, to);\n      }\n\n    } catch (InvalidOperationException e) {\n      if (e.getMessage() != null\n          && e.getMessage().contains(String.format(\"new table %s already exists\", to))) {\n        throw new AlreadyExistsException(\"Table already exists: %s\", to);\n      } else {\n        throw new RuntimeException(\"Failed to rename \" + from + \" to \" + to, e);\n      }\n\n    } catch (TException e) {\n      throw new RuntimeException(\"Failed to rename \" + from + \" to \" + to, e);\n\n    } catch (InterruptedException e) {\n      Thread.currentThread().interrupt();\n      throw new RuntimeException(\"Interrupted in call to rename\", e);\n    }\n  }\n\n  private void validateTableIsIcebergTableOrView(\n      HiveOperationsBase.ContentType contentType, Table table, String fullName) {\n    switch (contentType) {\n      case TABLE:\n        HiveOperationsBase.validateTableIsIceberg(table, fullName);","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java#L425-L461","documentation":"Thrown when the Hive Metastore rejects a rename with InvalidOperationException whose message contains 'new table <to> already exists'. Iceberg converts this into AlreadyExistsException, the catalog API's signal that the destination identifier is already taken. The source table/view is unchanged.","triggerScenarios":"Calling renameTable or renameView with a destination identifier 'to' that already exists as a table in the same Hive database.","commonSituations":"Renaming to a name that a previous partial run already created; two jobs renaming concurrently to the same target; re-running a non-idempotent migration script.","solutions":["Check catalog.tableExists(to) first and choose a unique destination name.","Drop or rename the existing destination table if it is stale/unwanted.","Make migration scripts idempotent: skip the rename when the target already exists and the source is gone."],"exampleFix":"// before\ncatalog.renameTable(from, to);\n// after\nif (!catalog.tableExists(to)) {\n  catalog.renameTable(from, to);\n}","handlingStrategy":"validation","validationCode":"if (catalog.tableExists(to)) { throw new IllegalArgumentException(\"Destination \" + to + \" already exists\"); }","typeGuard":null,"tryCatchPattern":"try { catalog.renameTable(from, to); } catch (org.apache.iceberg.exceptions.AlreadyExistsException e) { LOG.error(\"Destination {} already exists\", to, e); }","preventionTips":["Check destination existence before rename","Generate unique destination names (suffix with timestamp) in migrations","Make migration scripts idempotent","Avoid concurrent renames to the same target"],"tags":["hive-metastore","rename","already-exists","collision"],"backgroundTag":"file-already-exists","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}