{"record":{"id":"7e451ebb33f373c8","repo":"apache/iceberg","slug":"tablealreadyexistexception","errorCode":null,"errorMessage":"TableAlreadyExistException","messagePattern":"TableAlreadyExistException","errorType":"exception","errorClass":"TableAlreadyExistException","httpStatus":null,"severity":"error","filePath":"flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkCatalog.java","lineNumber":408,"sourceCode":"      if (!ignoreIfNotExists) {\n        throw new TableNotExistException(getName(), tablePath, e);\n      }\n    }\n  }\n\n  @Override\n  public void renameTable(ObjectPath tablePath, String newTableName, boolean ignoreIfNotExists)\n      throws TableNotExistException, TableAlreadyExistException, CatalogException {\n    try {\n      icebergCatalog.renameTable(\n          toIdentifier(tablePath),\n          toIdentifier(new ObjectPath(tablePath.getDatabaseName(), newTableName)));\n    } catch (org.apache.iceberg.exceptions.NoSuchTableException e) {\n      if (!ignoreIfNotExists) {\n        throw new TableNotExistException(getName(), tablePath, e);\n      }\n    } catch (AlreadyExistsException e) {\n      throw new TableAlreadyExistException(getName(), tablePath, e);\n    }\n  }\n\n  @Override\n  public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists)\n      throws CatalogException, TableAlreadyExistException {\n    // Creating Iceberg table using connector is allowed only when table is created using LIKE\n    if (Objects.equals(\n            table.getOptions().get(FlinkCreateTableOptions.CONNECTOR_PROPS_KEY),\n            FlinkDynamicTableFactory.FACTORY_IDENTIFIER)\n        && table.getOptions().get(FlinkCreateTableOptions.SRC_CATALOG_PROPS_KEY) == null) {\n      throw new IllegalArgumentException(\n          \"Cannot create the table with 'connector'='iceberg' table property in \"\n              + \"an iceberg catalog, Please create table with 'connector'='iceberg' property in a non-iceberg catalog or \"\n              + \"create table without 'connector'='iceberg' related properties in an iceberg table.\");\n    }\n\n    Preconditions.checkArgument(","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkCatalog.java#L390-L426","documentation":"Thrown by FlinkCatalog.renameTable when the target table name already exists in the Iceberg catalog (AlreadyExistsException), wrapped into Flink's TableAlreadyExistException. Iceberg's rename does not overwrite existing targets.","triggerScenarios":"Calling renameTable to a newTableName that already exists in the same database, with no pre-check.","commonSituations":"Retrying a partially completed rename; automated jobs generating colliding target names (e.g. timestamped names that already exist); attempting to swap tables by renaming over an existing one.","solutions":["Choose a target name that does not already exist, or drop/rename the existing target first.","Check tableExists on the target ObjectPath before renaming.","Catch TableAlreadyExistException and handle the collision in application logic."],"exampleFix":"// before\nflinkCatalog.renameTable(new ObjectPath(\"db\", \"old\"), \"existing\", false);\n// after\nObjectPath target = new ObjectPath(\"db\", \"existing\");\nif (!flinkCatalog.tableExists(target)) {\n  flinkCatalog.renameTable(new ObjectPath(\"db\", \"old\"), \"existing\", false);\n}","handlingStrategy":"validation","validationCode":"ObjectPath target = new ObjectPath(db, newName);\nif (flinkCatalog.tableExists(target)) { throw new IllegalStateException(\"target exists: \" + target); }","typeGuard":null,"tryCatchPattern":"try {\n  flinkCatalog.renameTable(tablePath, newName, false);\n} catch (TableAlreadyExistException e) {\n  // resolve collision: pick a new name or archive existing target\n}","preventionTips":["Check the target name does not exist before rename","Use unique, generated target names (timestamp+suffix)","Catch the exception in automated pipelines to resolve collisions"],"tags":["flink","catalog","rename","name-conflict"],"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-23T08:17:48.524Z"}