{"record":{"id":"604c070b0a81f806","repo":"apache/iceberg","slug":"view-already-exists-s-s","errorCode":null,"errorMessage":"View already exists: %s.%s","messagePattern":"View already exists: (.+?)\\.(.+?)","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":null,"severity":"error","filePath":"hive-metastore/src/main/java/org/apache/iceberg/hive/HiveViewOperations.java","lineNumber":203,"sourceCode":"          currentMetadataLocation(),\n          sqlFor(metadata));\n      lock.ensureActive();\n\n      try {\n        persistTable(tbl, updateHiveView, hiveLockEnabled(conf) ? null : baseMetadataLocation);\n        lock.ensureActive();\n\n        commitStatus = CommitStatus.SUCCESS;\n      } catch (LockException le) {\n        commitStatus = CommitStatus.UNKNOWN;\n        throw new CommitStateUnknownException(\n            \"Failed to heartbeat for hive lock while \"\n                + \"committing changes. This can lead to a concurrent commit attempt be able to overwrite this commit. \"\n                + \"Please check the commit history. If you are running into this issue, try reducing \"\n                + \"iceberg.hive.lock-heartbeat-interval-ms.\",\n            le);\n      } catch (org.apache.hadoop.hive.metastore.api.AlreadyExistsException e) {\n        throw new AlreadyExistsException(e, \"View already exists: %s.%s\", database, viewName);\n\n      } catch (InvalidObjectException e) {\n        throw new ValidationException(e, \"Invalid Hive object for %s.%s\", database, viewName);\n\n      } catch (CommitFailedException | CommitStateUnknownException e) {\n        throw e;\n\n      } catch (Throwable e) {\n        if (e.getMessage() != null\n            && e.getMessage()\n                .contains(\n                    \"The table has been modified. The parameter value for key '\"\n                        + BaseMetastoreTableOperations.METADATA_LOCATION_PROP\n                        + \"' is\")) {\n          throw new CommitFailedException(\n              e, \"The view %s.%s has been modified concurrently\", database, viewName);\n        }\n","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveViewOperations.java#L185-L221","documentation":"doCommit maps Hive metastore's org.apache.hadoop.hive.metastore.api.AlreadyExistsException to Iceberg's AlreadyExistsException with \"View already exists: database.viewName\". This is raised when the metastore rejects the create/alter because an object with that name already exists, e.g., a concurrent create won the race.","triggerScenarios":"Committing a view creation when HMS raises its native AlreadyExistsException — an object (view or table) named database.viewName already exists in the metastore at alter/create time.","commonSituations":"Concurrent view creation by two clients; retrying create after an ambiguous first attempt that actually succeeded; name collisions with existing tables; double submission of the same DDL job.","solutions":["Catch AlreadyExistsException and fall back to loading or replacing the existing view.","Check existence first with catalog.viewExists, but keep the catch for the inherent race.","Pick a different view name or drop the conflicting object intentionally before creating.","Deduplicate DDL submissions in your orchestration to avoid double creates."],"exampleFix":"// before\nviews.createView(identifier, ...); // AlreadyExistsException on race\n// after\ntry {\n  views.createView(identifier, ...);\n} catch (AlreadyExistsException e) {\n  views.loadView(identifier); // adopt existing\n}","handlingStrategy":"try-catch","validationCode":"if (catalog.viewExists(identifier)) {\n  throw new IllegalStateException(\"View \" + identifier + \" already exists; use replace instead of create\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  views.createView(identifier, ...);\n} catch (AlreadyExistsException e) {\n  views.loadView(identifier); // adopt or replaceView instead\n}","preventionTips":["Prefer create-or-replace semantics for idempotent pipelines.","Guard concurrent creates with an external lock or orchestrator.","Deduplicate DDL submissions and retries.","Choose unique names per environment to avoid collisions."],"tags":["hive-metastore","view","already-exists","concurrency"],"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"}