{"record":{"id":"3968142638b82259","repo":"prestodb/presto","slug":"duplicatemapkeyexception","errorCode":null,"errorMessage":"DuplicateMapKeyException","messagePattern":"DuplicateMapKeyException","errorType":"exception","errorClass":"DuplicateMapKeyException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/MapBlockBuilder.java","lineNumber":591,"sourceCode":"\n                Boolean isDuplicateKey;\n                try {\n                    // assuming maps with indeterminate keys are not supported\n                    isDuplicateKey = (Boolean) keyBlockEquals.invokeExact(keyBlock, keyOffset + i, keyBlock, keyOffset + outputHashTable[hashTableOffset + hash]);\n                }\n                catch (RuntimeException e) {\n                    throw e;\n                }\n                catch (Throwable throwable) {\n                    throw new RuntimeException(throwable);\n                }\n\n                if (isDuplicateKey == null) {\n                    throw new NotSupportedException(\"map key cannot be null or contain nulls\");\n                }\n\n                if (isDuplicateKey) {\n                    throw new DuplicateMapKeyException(keyBlock, keyOffset + i);\n                }\n\n                hash++;\n                if (hash == hashTableSize) {\n                    hash = 0;\n                }\n            }\n        }\n    }\n\n    private static int getHashPosition(Block keyBlock, int position, MethodHandle keyBlockHashCode, int hashTableSize)\n    {\n        if (keyBlock.isNull(position)) {\n            throw new IllegalArgumentException(\"map keys cannot be null\");\n        }\n\n        long hashCode;\n        try {","sourceCodeStart":573,"sourceCodeEnd":609,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/MapBlockBuilder.java#L573-L609","documentation":"DuplicateMapKeyException is thrown by buildHashTableStrict (via closeEntryStrict) when inserting a key into the open-addressing hash table finds the key already present. Presto maps enforce key uniqueness at build time in strict mode, so writing a second entry with an equal key fails. The exception message is the class name and it is special-cased by Presto's error handling for retry semantics.","triggerScenarios":"Calling closeEntryStrict twice with equal keys on the same MapBlockBuilder, e.g. map_from_entries with duplicate entries, or a map constructor fed repeated keys.","commonSituations":"SQL like map_from_entries(ARRAY[(1,'a'),(1,'b')]); upstream data with duplicate join/lookup keys feeding map construction.","solutions":["Deduplicate entries before building the map","Use a function that tolerates duplicates (e.g. keep-last semantics) if available","Report a clear user-facing error that input entries contain duplicate keys"],"exampleFix":"// before\nbuilder.key(keyBlock, pos).value(...).closeEntryStrict(); // '1' already added\n// after\nSet<Integer> seen = new HashSet<>();\ncheckState(seen.add(keyHash), \"duplicate key in map entries\");\nbuilder.key(keyBlock, pos).value(...).closeEntryStrict();","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    builder.closeEntryStrict();\n} catch (DuplicateMapKeyException e) {\n    // handle duplicate key: report position e.getPosition() or deduplicate and retry\n}","preventionTips":["Deduplicate entry keys before building the map","Use try_cast/hash-based dedup upstream","Surface duplicate-key inputs as user-facing data errors"],"tags":["duplicate-key","map-block","hash-table"],"backgroundTag":"duplicate-map-key","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}