{"record":{"id":"23b84fe820da685a","repo":"prestodb/presto","slug":"generic-internal-error-23b84f","errorCode":"GENERIC_INTERNAL_ERROR","errorMessage":"Map must never contain null keys","messagePattern":"Map must never contain null keys","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-rcfile/src/main/java/com/facebook/presto/rcfile/binary/MapEncoding.java","lineNumber":55,"sourceCode":"        super(type);\n        this.keyReader = keyReader;\n        this.valueReader = valueReader;\n    }\n\n    @Override\n    public void encodeValue(Block block, int position, SliceOutput output)\n    {\n        Block map = block.getBlock(position);\n\n        // write entry count\n        writeVInt(output, map.getPositionCount() / 2);\n\n        // write null bits\n        int nullByte = 0b0101_0101;\n        int bits = 0;\n        for (int elementIndex = 0; elementIndex < map.getPositionCount(); elementIndex += 2) {\n            if (map.isNull(elementIndex)) {\n                throw new PrestoException(StandardErrorCode.GENERIC_INTERNAL_ERROR, \"Map must never contain null keys\");\n            }\n\n            if (bits == 8) {\n                output.writeByte(nullByte);\n                nullByte = 0b0101_0101;\n                bits = 0;\n            }\n\n            if (!map.isNull(elementIndex + 1)) {\n                nullByte |= (1 << bits + 1);\n            }\n            bits += 2;\n        }\n        output.writeByte(nullByte);\n\n        // write values\n        for (int elementIndex = 0; elementIndex < map.getPositionCount(); elementIndex += 2) {\n            if (map.isNull(elementIndex)) {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-rcfile/src/main/java/com/facebook/presto/rcfile/binary/MapEncoding.java#L37-L73","documentation":"RCBinary MapEncoding writes maps key-by-key and cannot represent null keys in its null-bitmap layout. Since Presto guarantees map keys are never null, a null key indicates an internal invariant violation, so it throws PrestoException(GENERIC_INTERNAL_ERROR).","triggerScenarios":"encodeValue iterating a Block-backed map where map.isNull(elementIndex) is true at an even (key) position — i.e. a MapBlock with a null key, which should be impossible via normal Presto SQL.","commonSituations":"Hand-constructed or connector-supplied MapBlocks violating the no-null-keys invariant; custom UDFs or connectors building map blocks with null keys; corrupted block construction in extensions.","solutions":["Fix the producer (connector/UDF) to never build map blocks containing null keys","Validate/rewrite the block: filter or fail on null keys before encoding","Rebuild the map in SQL with a filter (WHERE key IS NOT NULL) upstream","Catch PrestoException with GENERIC_INTERNAL_ERROR and report as a bug with the query/connector involved"],"exampleFix":"// before (producer) someMap.put(null, value);\n// after\nif (key == null) { throw new IllegalArgumentException(\"null map key\"); } else { someMap.put(key, value); }","handlingStrategy":"validation","validationCode":"// before encoding a map block\nBlock map = block.getBlock(position);\nfor (int i = 0; i < map.getPositionCount(); i += 2) {\n    if (map.isNull(i)) { throw new IllegalArgumentException(\"null map key at position \" + i); }\n}","typeGuard":null,"tryCatchPattern":"try { mapEncoding.encodeValue(...); }\ncatch (PrestoException e) {\n    if (e.getErrorCode().getCode() == StandardErrorCode.GENERIC_INTERNAL_ERROR.toErrorCode().getCode()) {\n        reportBug(e); // invariant violated by block producer\n    } else { throw e; }\n}","preventionTips":["Never build MapBlocks with null keys in connectors/UDFs","Enforce the map contract in unit tests for custom block producers","Use map_filter(m, (k,v) -> k IS NOT NULL) upstream in SQL","Sanitize connector output before handing blocks to the writer"],"tags":["rcfile","map","null-keys","internal-error"],"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"}