{"record":{"id":"7c43b2171ad6e584","repo":"apache/iceberg","slug":"viewalreadyexistsexception-toidentifier-7c43b2","errorCode":null,"errorMessage":"ViewAlreadyExistsException(toIdentifier)","messagePattern":"ViewAlreadyExistsException\\(toIdentifier\\)","errorType":"exception","errorClass":"ViewAlreadyExistsException","httpStatus":409,"severity":"error","filePath":"spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java","lineNumber":784,"sourceCode":"  @Override\n  public boolean dropView(Identifier ident) {\n    if (null != asViewCatalog) {\n      return asViewCatalog.dropView(buildIdentifier(ident));\n    }\n\n    return false;\n  }\n\n  @Override\n  public void renameView(Identifier fromIdentifier, Identifier toIdentifier)\n      throws NoSuchViewException, ViewAlreadyExistsException {\n    if (null != asViewCatalog) {\n      try {\n        asViewCatalog.renameView(buildIdentifier(fromIdentifier), buildIdentifier(toIdentifier));\n      } catch (org.apache.iceberg.exceptions.NoSuchViewException e) {\n        throw new NoSuchViewException(fromIdentifier);\n      } catch (org.apache.iceberg.exceptions.AlreadyExistsException e) {\n        throw new ViewAlreadyExistsException(toIdentifier);\n      }\n    } else {\n      throw new UnsupportedOperationException(\n          \"Renaming a view is not supported by catalog: \" + catalogName);\n    }\n  }\n\n  @Override\n  public final void initialize(String name, CaseInsensitiveStringMap options) {\n    super.initialize(name, options);\n\n    boolean cacheEnabled =\n        PropertyUtil.propertyAsBoolean(\n            options, CatalogProperties.CACHE_ENABLED, CatalogProperties.CACHE_ENABLED_DEFAULT);\n\n    boolean cacheCaseSensitive =\n        PropertyUtil.propertyAsBoolean(\n            options,","sourceCodeStart":766,"sourceCodeEnd":802,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java#L766-L802","documentation":"Thrown by SparkCatalog.renameView when the underlying Iceberg view catalog raises AlreadyExistsException, i.e., a view (or conflicting object) already exists at the destination identifier. Spark translates this into ViewAlreadyExistsException for toIdentifier and the rename is not performed.","triggerScenarios":"ALTER VIEW from RENAME TO to where toIdentifier already names an existing view in the catalog.","commonSituations":"Destination name already taken by a prior view; rerunning a migration script; case-insensitive filesystem-backed catalogs making names collide.","solutions":["Drop or rename the existing view at the destination first","Choose a different destination name","Check SHOW VIEWS in the destination namespace to confirm the name is free"],"exampleFix":"// before\nALTER VIEW catalog.db.v1 RENAME TO catalog.db.v2; // v2 exists\n// after\nDROP VIEW catalog.db.v2;\nALTER VIEW catalog.db.v1 RENAME TO catalog.db.v2;","handlingStrategy":"validation","validationCode":"if (spark.catalog().viewExists(\"catalog\", \"db\", \"to\")) { spark.sql(\"DROP VIEW catalog.db.to\"); } // then rename","typeGuard":null,"tryCatchPattern":"try {\n  catalog.renameView(fromIdent, toIdent);\n} catch (ViewAlreadyExistsException e) {\n  // drop destination or pick a new name\n}","preventionTips":["Check destination name availability before rename","Make rename scripts idempotent (drop-if-exists destination)","Avoid generic names like v1/v2 that collide easily"],"tags":["spark","view","rename","already-exists"],"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-14T16:17:12.679Z"}