apache/iceberg · error · ViewAlreadyExistsException

ViewAlreadyExistsException(toIdentifier)

Error message

ViewAlreadyExistsException(toIdentifier)

What it means

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.

Source

Thrown at spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java:784

  @Override
  public boolean dropView(Identifier ident) {
    if (null != asViewCatalog) {
      return asViewCatalog.dropView(buildIdentifier(ident));
    }

    return false;
  }

  @Override
  public void renameView(Identifier fromIdentifier, Identifier toIdentifier)
      throws NoSuchViewException, ViewAlreadyExistsException {
    if (null != asViewCatalog) {
      try {
        asViewCatalog.renameView(buildIdentifier(fromIdentifier), buildIdentifier(toIdentifier));
      } catch (org.apache.iceberg.exceptions.NoSuchViewException e) {
        throw new NoSuchViewException(fromIdentifier);
      } catch (org.apache.iceberg.exceptions.AlreadyExistsException e) {
        throw new ViewAlreadyExistsException(toIdentifier);
      }
    } else {
      throw new UnsupportedOperationException(
          "Renaming a view is not supported by catalog: " + catalogName);
    }
  }

  @Override
  public final void initialize(String name, CaseInsensitiveStringMap options) {
    super.initialize(name, options);

    boolean cacheEnabled =
        PropertyUtil.propertyAsBoolean(
            options, CatalogProperties.CACHE_ENABLED, CatalogProperties.CACHE_ENABLED_DEFAULT);

    boolean cacheCaseSensitive =
        PropertyUtil.propertyAsBoolean(
            options,

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Drop or rename the existing view at the destination first
  2. Choose a different destination name
  3. Check SHOW VIEWS in the destination namespace to confirm the name is free

Example fix

// before
ALTER VIEW catalog.db.v1 RENAME TO catalog.db.v2; // v2 exists
// after
DROP VIEW catalog.db.v2;
ALTER VIEW catalog.db.v1 RENAME TO catalog.db.v2;
Defensive patterns

Strategy: validation

Validate before calling

if (spark.catalog().viewExists("catalog", "db", "to")) { spark.sql("DROP VIEW catalog.db.to"); } // then rename

Try / catch

try {
  catalog.renameView(fromIdent, toIdent);
} catch (ViewAlreadyExistsException e) {
  // drop destination or pick a new name
}

Prevention

When it happens

Trigger: ALTER VIEW from RENAME TO to where toIdentifier already names an existing view in the catalog.

Common situations: Destination name already taken by a prior view; rerunning a migration script; case-insensitive filesystem-backed catalogs making names collide.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/7c43b2171ad6e584. Report an issue: GitHub.