{"record":{"id":"dfd50f0af89acc58","repo":"apache/iceberg","slug":"view-with-same-name-already-exists-s-s","errorCode":null,"errorMessage":"View with same name already exists: %s.%s","messagePattern":"View with same name already exists: (.+?)\\.(.+?)","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":409,"severity":"error","filePath":"hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java","lineNumber":283,"sourceCode":"\n    BaseMetastoreOperations.CommitStatus commitStatus =\n        BaseMetastoreOperations.CommitStatus.FAILURE;\n    boolean updateHiveTable = false;\n\n    HiveLock lock = lockObject(base != null ? base : tableMetadata);\n    try {\n      lock.lock();\n\n      Table tbl = loadHmsTable();\n\n      if (tbl != null) {\n        // If we try to create the table but the metadata location is already set, then we had a\n        // concurrent commit\n        if (newTable\n            && tbl.getParameters().get(BaseMetastoreTableOperations.METADATA_LOCATION_PROP)\n                != null) {\n          if (TableType.VIRTUAL_VIEW.name().equalsIgnoreCase(tbl.getTableType())) {\n            throw new AlreadyExistsException(\n                \"View with same name already exists: %s.%s\", database, tableName);\n          }\n          throw new AlreadyExistsException(\"Table already exists: %s.%s\", database, tableName);\n        }\n\n        updateHiveTable = true;\n        LOG.debug(\"Committing existing table: {}\", fullName);\n      } else {\n        tbl =\n            newHmsTable(\n                tableMetadata.property(HiveCatalog.HMS_TABLE_OWNER, HiveHadoopUtil.currentUser()));\n        LOG.debug(\"Committing new table: {}\", fullName);\n      }\n\n      tbl.setSd(\n          HiveOperationsBase.storageDescriptor(\n              tableMetadata.schema(),\n              tableMetadata.location(),","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java#L265-L301","documentation":"HiveTableOperations.doCommit throws AlreadyExistsException when it attempts to create a new table in HMS but an entity of type VIRTUAL_VIEW with the same name already exists AND already carries the Iceberg metadata-location property — meaning a concurrent commit created it first, as a view. It protects against silently overwriting a concurrently created Iceberg view.","triggerScenarios":"Concurrent createView operations racing on the same identifier: both see the table as absent (newTable), but the first commit lands, so the loser's create path finds the entity with METADATA_LOCATION_PROP set and tableType VIRTUAL_VIEW.","commonSituations":"Two jobs or engines creating the same Iceberg view simultaneously; retry logic re-running a create after an ambiguous first attempt; duplicate scheduled jobs.","solutions":["Catch AlreadyExistsException and re-load the view — the concurrent creation succeeded and its result is authoritative.","Deduplicate creation logic so only one process creates the view (idempotent create-or-load pattern).","If the concurrent view is wrong, drop it and recreate with the intended definition after coordination."],"exampleFix":"// before\nview = catalog.buildView(ident).withQuery(\"sql\").create(); // races\n// after\ntry { view = catalog.buildView(ident).withQuery(\"sql\").create(); }\ncatch (AlreadyExistsException e) { view = catalog.loadView(ident); }","handlingStrategy":"try-catch","validationCode":"boolean exists = catalog.viewExists(ident); // only one coordinator should create when false","typeGuard":null,"tryCatchPattern":"try { view = catalog.buildView(ident).withQuery(sql).create(); } catch (AlreadyExistsException e) { view = catalog.loadView(ident); }","preventionTips":["Use idempotent create-or-load patterns for views.","Serialize create operations through a single orchestrator.","Deduplicate scheduled jobs that create the same view."],"tags":["concurrency","already-exists","hive-metastore","view"],"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"}