{"record":{"id":"b6517856244b8baf","repo":"prestodb/presto","slug":"map-key-cannot-be-null-or-contain-nulls-b65178","errorCode":null,"errorMessage":"map key cannot be null or contain nulls","messagePattern":"map key cannot be null or contain nulls","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/SingleMapBlock.java","lineNumber":458,"sourceCode":"            position++;\n            if (position == hashTableSize) {\n                position = 0;\n            }\n        }\n    }\n\n    private static RuntimeException handleThrowable(Throwable throwable)\n    {\n        if (throwable instanceof Error) {\n            throw (Error) throwable;\n        }\n        throw new GenericInternalException(throwable);\n    }\n\n    private static void checkNotIndeterminate(Boolean equalsResult)\n    {\n        if (equalsResult == null) {\n            throw new NotSupportedException(\"map key cannot be null or contain nulls\");\n        }\n    }\n\n    @Override\n    public boolean equals(Object obj)\n    {\n        if (this == obj) {\n            return true;\n        }\n        if (obj == null || getClass() != obj.getClass()) {\n            return false;\n        }\n        SingleMapBlock other = (SingleMapBlock) obj;\n        return this.positionInMap == other.positionInMap &&\n                this.offset == other.offset &&\n                this.positionCount == other.positionCount &&\n                Objects.equals(this.mapBlock, other.mapBlock);\n    }","sourceCodeStart":440,"sourceCodeEnd":476,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/SingleMapBlock.java#L440-L476","documentation":"SingleMapBlock's key lookup (seekKey/seekKeyExact) relies on Boolean equality results for keys. checkNotIndeterminate throws NotSupportedException when the equals comparison returns null, which happens when the key is NULL or contains nulls — map keys in Presto must be determinate (non-null). Equality with indeterminate keys cannot produce a valid true/false answer, so lookup fails fast.","triggerScenarios":"Calling seekKey or seekKeyExact with a key that is null, or whose type contains null subfields (e.g. a row/array key with null elements), causing the block's equals comparison to return Boolean null.","commonSituations":"Querying a map column with a NULL key constant, JOIN/filter predicates comparing map keys against nullable expressions, using MAP with ROW keys that have null fields.","solutions":["Filter out NULL keys before lookup: add IS NOT NULL predicate on the key expression.","Use COALESCE to substitute a sentinel non-null value for keys used in lookups.","Avoid indeterminate types (types containing nulls) as map keys; use COALESCE on inner fields of composite keys.","Return NULL from the surrounding operator when the key is indeterminate instead of performing seekKey."],"exampleFix":"// before\n// seekKey(keyBlock) where key may be NULL\nboolean found = singleMapBlock.seekKeyExact(keyBlock, keyPosition);\n// after\nif (keyBlock.isNull(keyPosition)) {\n    return null; // indeterminate key: no match possible\n}\nboolean found = singleMapBlock.seekKeyExact(keyBlock, keyPosition);","handlingStrategy":"validation","validationCode":"boolean isIndeterminateKey(Block keyBlock, int position) {\n    return keyBlock.isNull(position) || containsNull(keyBlock, position);\n}\n// guard:\nif (keyBlock.isNull(keyPosition)) { return null; } // skip lookup","typeGuard":"boolean isDeterminanteKey(Block keyBlock, int position) {\n    return !keyBlock.isNull(position);\n}","tryCatchPattern":"try {\n    return singleMapBlock.seekKeyExact(keyBlock, keyPosition);\n} catch (NotSupportedException e) {\n    if (e.getMessage().contains(\"map key cannot be null or contain nulls\")) {\n        return null; // indeterminate key never matches\n    }\n    throw e;\n}","preventionTips":["Prevent NULL map keys at write time (reject or COALESCE during ETL).","Avoid composite (ROW/ARRAY) key types whose fields can be null.","Add IS NOT NULL predicates before key-based lookups in queries."],"tags":["presto","map-block","null-key","indeterminate"],"backgroundTag":"null-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"}