{"record":{"id":"5ffddad4224d2428","repo":"apache/iceberg","slug":"failed-to-rename-from-to-to","errorCode":null,"errorMessage":"Failed to rename ${from} to ${to}","messagePattern":"Failed to rename (.+?) to (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java","lineNumber":445,"sourceCode":"            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);\n        break;\n      case VIEW:","sourceCodeStart":427,"sourceCodeEnd":463,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java#L427-L463","documentation":"A generic RuntimeException wrapping an InvalidOperationException from the Hive Metastore during rename when the exception message does NOT indicate an existing destination. It means the metastore refused the operation for another reason (e.g. invalid operation on the object type), and Iceberg has no more specific mapping. The original exception is attached as the cause.","triggerScenarios":"renameTable/renameView where the metastore throws InvalidOperationException with a message other than 'new table <to> already exists', e.g. metastore-side restrictions on the operation.","commonSituations":"Older Hive Metastore versions with different error text (the string match on 'already exists' misses it, downgrading an AlreadyExists case to this generic error); metastore configuration forbidding renames; renaming objects the metastore treats specially.","solutions":["Inspect the cause (e.getCause()) message to learn the actual metastore rejection reason.","If the real cause is a name collision (older HMS error wording), drop/rename the destination first or upgrade to a version with better mapping.","Check Hive Metastore version compatibility and metastore event/authorization configs that may block renames."],"exampleFix":"// before\ncatalog.renameTable(from, to);\n// after\ntry {\n  catalog.renameTable(from, to);\n} catch (RuntimeException e) {\n  LOG.error(\"Rename rejected by metastore\", e.getCause());\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { catalog.renameTable(from, to); } catch (RuntimeException e) { LOG.error(\"Metastore rejected rename: {}\", e.getCause() != null ? e.getCause().getMessage() : e.getMessage(), e); throw e; }","preventionTips":["Always log/inspect getCause() for the real metastore rejection","Keep Hive Metastore and Iceberg versions aligned","Do not rely on exception-message string matching yourself"],"tags":["hive-metastore","rename","invalid-operation","runtime-exception"],"backgroundTag":"invalid-state-transition","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"}