{"record":{"id":"0e455b4d22b3094c","repo":"apache/iceberg","slug":"s-already-exists-s-s","errorCode":null,"errorMessage":"%s already exists: %s.%s","messagePattern":"(.+?) already exists: (.+?)\\.(.+?)","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":null,"severity":"error","filePath":"hive-metastore/src/main/java/org/apache/iceberg/hive/HiveViewOperations.java","lineNumber":140,"sourceCode":"    String newMetadataLocation = writeNewMetadataIfRequired(metadata);\n    boolean hiveEngineEnabled = false;\n\n    CommitStatus commitStatus = CommitStatus.FAILURE;\n    boolean updateHiveView = false;\n\n    HiveLock lock = lockObject();\n    try {\n      lock.lock();\n\n      Table tbl = loadHmsTable();\n\n      if (tbl != null) {\n        // If we try to create the view but the metadata location is already set, then we had a\n        // concurrent commit\n        if (newView\n            && tbl.getParameters().get(BaseMetastoreTableOperations.METADATA_LOCATION_PROP)\n                != null) {\n          throw new AlreadyExistsException(\n              \"%s already exists: %s.%s\",\n              TableType.VIRTUAL_VIEW.name().equalsIgnoreCase(tbl.getTableType())\n                  ? ContentType.VIEW.value()\n                  : ContentType.TABLE.value(),\n              database,\n              viewName);\n        }\n\n        updateHiveView = true;\n        LOG.debug(\"Committing existing view: {}\", fullName);\n      } else {\n        tbl = newHMSView(metadata);\n        LOG.debug(\"Committing new view: {}\", fullName);\n      }\n\n      tbl.setSd(\n          HiveOperationsBase.storageDescriptor(\n              metadata.schema(),","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveViewOperations.java#L122-L158","documentation":"HiveViewOperations.doCommit throws AlreadyExistsException when attempting to create a new view but the HMS table already exists and has a METADATA_LOCATION_PROP set. If the existing object is a VIRTUAL_VIEW it reports a \"view already exists\", otherwise a \"table already exists\" — this detects a concurrent create that won the race.","triggerScenarios":"Calling createView (doCommit with newView=true) while another client concurrently created the same view (or a table with the same name) in the metastore, so the HMS getView/alter path finds an existing object with metadata location already set.","commonSituations":"Two jobs creating the same view concurrently; retrying a create after an ambiguous failure when the first attempt actually succeeded; name collision between a view and an existing table in the same database.","solutions":["Catch AlreadyExistsException and load the existing view instead of creating it (create-or-replace semantics via replaceView).","Use catalog-level existence checks (catalog.viewExists) before create, accepting the race and handling the exception.","Rename your view or choose a different namespace if the collision is with an unintended table.","Coordinate DDL across jobs (external locking or orchestration) to avoid concurrent creates."],"exampleFix":"// before\nviews.createView(identifier, schema, spec, null, location, props); // races\n// after\ntry {\n  views.createView(identifier, schema, spec, null, location, props);\n} catch (AlreadyExistsException e) {\n  View existing = views.loadView(identifier); // use or replace existing\n}","handlingStrategy":"try-catch","validationCode":"if (catalog.viewExists(identifier)) {\n  // decide: adopt, replace, or abort instead of creating\n}","typeGuard":null,"tryCatchPattern":"try {\n  views.createView(identifier, schema, spec, null, location, props);\n} catch (AlreadyExistsException e) {\n  View existing = views.loadView(identifier); // handle concurrent create\n}","preventionTips":["Use idempotent create-or-replace flows rather than blind create.","Serialize concurrent DDL on the same view name via orchestration.","Deduplicate retried create jobs.","Avoid reusing names across views and tables in the same database."],"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"}