apache/iceberg · error · AlreadyExistsException
View with same name already exists: %s
Error message
View with same name already exists: %s
What it means
HiveCatalog's view-builder createOrReplaceTransaction() throws AlreadyExistsException when a view already exists under the target identifier. Because the requested operation is a create-or-replace transaction, an existing view of the same name is a hard conflict: replace transactions refuse to silently overwrite a pre-existing view. The check runs before the transaction is opened so no partial metadata is written.
Source
Thrown at hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java:911
/**
* The purpose of this class is to add view detection only for Hive-Specific tables. Hive catalog
* follows checks at different levels: 1. During refresh, it validates if the table is an iceberg
* table or not. 2. During commit, it validates if there is any concurrent commit with table or
* table-name already exists. This class helps to do the validation on an early basis.
*/
private class ViewAwareTableBuilder extends BaseMetastoreViewCatalogTableBuilder {
private final TableIdentifier identifier;
private ViewAwareTableBuilder(TableIdentifier identifier, Schema schema) {
super(identifier, schema);
this.identifier = identifier;
}
@Override
public Transaction createOrReplaceTransaction() {
if (viewExists(identifier)) {
throw new AlreadyExistsException("View with same name already exists: %s", identifier);
}
return super.createOrReplaceTransaction();
}
@Override
public org.apache.iceberg.Table create() {
if (viewExists(identifier)) {
throw new AlreadyExistsException("View with same name already exists: %s", identifier);
}
return super.create();
}
}
/**
* The purpose of this class is to add table detection only for Hive-Specific view. Hive catalog
* follows checks at different levels: 1. During refresh, it validates if the view is an iceberg
* view or not. 2. During commit, it validates if there is any concurrent commit with view or
* view-name already exists. This class helps to do the validation on an early basis.View on GitHub (pinned to 86d9c8fc54)
Solutions
- Delete or rename the existing view first: catalog.dropView(identifier), then re-run createOrReplaceTransaction().
- Guard the call with if (!catalog.viewExists(identifier)) before creating, or wrap in try-catch for AlreadyExistsException and treat it as a no-op.
- If the intent is to replace a table with a view (or vice versa), drop the conflicting object explicitly since create-or-replace only replaces same-type objects.
- Use locking or a single writer for concurrent view creation jobs to avoid races.
Example fix
// before
catalog.buildView(identifier).createOrReplaceTransaction();
// after
if (catalog.viewExists(identifier)) {
catalog.dropView(identifier); // or skip creation if the view is current
}
catalog.buildView(identifier).createOrReplaceTransaction(); Defensive patterns
Strategy: validation
Validate before calling
if (catalog.viewExists(identifier)) {
// handle existing view before createOrReplaceTransaction()
} Try / catch
try {
catalog.buildView(identifier).createOrReplaceTransaction();
} catch (AlreadyExistsException e) {
// view already exists: skip, drop, or reconcile
} Prevention
- Check viewExists before any create-or-replace call
- Make deployment scripts idempotent with explicit drop-or-skip logic
- Serialize concurrent view creation with external locking or single-writer jobs
When it happens
Trigger: Calling HiveCatalog.buildView(identifier).createOrReplaceTransaction() (or createOrReplace()) when a view with the same namespace-qualified name already exists in the Hive Metastore. The viewExists(identifier) check inside HiveCatalog's ViewBuilder returns true immediately before super.createOrReplaceTransaction() runs.
Common situations: Double-submitting a view-creation job; concurrent pipelines racing to create the same view name; re-running idempotent-expected deployment scripts that don't first check existence; a table and view name collision where an older view was left behind after a migration.
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
- Table with same name already exists: %s
- Cannot create namespace %s: already exists
- Table already exists: %s
- Namespace already exists: %s
- View with same name already exists: %s
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/57f17f482e604b1d.
Report an issue: GitHub.