{"record":{"id":"1930f50f472a4ee2","repo":"apache/iceberg","slug":"view-already-exists-toidentifier","errorCode":null,"errorMessage":"View already exists: toIdentifier","messagePattern":"View already exists: toIdentifier","errorType":"exception","errorClass":"ViewAlreadyExistsException","httpStatus":409,"severity":"error","filePath":"spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java","lineNumber":757,"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    this.cacheEnabled =\n        PropertyUtil.propertyAsBoolean(\n            options, CatalogProperties.CACHE_ENABLED, CatalogProperties.CACHE_ENABLED_DEFAULT);\n\n    boolean cacheCaseSensitive =\n        PropertyUtil.propertyAsBoolean(\n            options,","sourceCodeStart":739,"sourceCodeEnd":775,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java#L739-L775","documentation":"Thrown by SparkCatalog.renameView when the underlying view catalog throws AlreadyExistsException for the target identifier, meaning a view (or conflicting object) named toIdentifier already exists. The source view is left unchanged and the rename fails atomically.","triggerScenarios":"Calling renameView(fromIdentifier, toIdentifier) where a view named toIdentifier already exists in the view catalog; the catalog's renameView rejects the name collision and SparkCatalog maps it to ViewAlreadyExistsException.","commonSituations":"Renaming a view to a name that already exists (e.g. daily -> daily_backup where daily_backup exists); rerunning an idempotent rename script after a previous partial success; case-insensitive filesystems or catalogs where the names collide after normalization.","solutions":["Drop or rename the existing target view first, or choose a different target name.","Check existence with SHOW VIEWS / viewExists(toIdentifier) before renaming.","If the collision is unintended (stale artifact), drop the stale view and retry.","For idempotent pipelines, wrap the rename in logic that treats 'target already equals source' as success."],"exampleFix":"// before\nspark.sql(\"ALTER VIEW analytics.daily RENAME TO analytics.backup\");\n// after\nspark.sql(\"DROP VIEW IF EXISTS analytics.backup\");\nspark.sql(\"ALTER VIEW analytics.daily RENAME TO analytics.backup\");","handlingStrategy":"validation","validationCode":"if (catalog.viewExists(toIdentifier)) { throw new IllegalStateException(\"target view already exists: \" + toIdentifier); }","typeGuard":null,"tryCatchPattern":"try { catalog.renameView(from, to); } catch (ViewAlreadyExistsException e) { catalog.dropView(to); catalog.renameView(from, to); }","preventionTips":["Drop or verify the target name first","Generate unique target names (suffix with timestamp)","Make idempotent scripts handle pre-existing targets"],"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"}