prestodb/presto · error · PrestoException

GENERIC_INTERNAL_ERROR

GENERIC_INTERNAL_ERROR

Error message

Map must never contain null keys

What it means

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).

Source

Thrown at presto-rcfile/src/main/java/com/facebook/presto/rcfile/binary/MapEncoding.java:55

        super(type);
        this.keyReader = keyReader;
        this.valueReader = valueReader;
    }

    @Override
    public void encodeValue(Block block, int position, SliceOutput output)
    {
        Block map = block.getBlock(position);

        // write entry count
        writeVInt(output, map.getPositionCount() / 2);

        // write null bits
        int nullByte = 0b0101_0101;
        int bits = 0;
        for (int elementIndex = 0; elementIndex < map.getPositionCount(); elementIndex += 2) {
            if (map.isNull(elementIndex)) {
                throw new PrestoException(StandardErrorCode.GENERIC_INTERNAL_ERROR, "Map must never contain null keys");
            }

            if (bits == 8) {
                output.writeByte(nullByte);
                nullByte = 0b0101_0101;
                bits = 0;
            }

            if (!map.isNull(elementIndex + 1)) {
                nullByte |= (1 << bits + 1);
            }
            bits += 2;
        }
        output.writeByte(nullByte);

        // write values
        for (int elementIndex = 0; elementIndex < map.getPositionCount(); elementIndex += 2) {
            if (map.isNull(elementIndex)) {

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Fix the producer (connector/UDF) to never build map blocks containing null keys
  2. Validate/rewrite the block: filter or fail on null keys before encoding
  3. Rebuild the map in SQL with a filter (WHERE key IS NOT NULL) upstream
  4. Catch PrestoException with GENERIC_INTERNAL_ERROR and report as a bug with the query/connector involved

Example fix

// before (producer) someMap.put(null, value);
// after
if (key == null) { throw new IllegalArgumentException("null map key"); } else { someMap.put(key, value); }
Defensive patterns

Strategy: validation

Validate before calling

// before encoding a map block
Block map = block.getBlock(position);
for (int i = 0; i < map.getPositionCount(); i += 2) {
    if (map.isNull(i)) { throw new IllegalArgumentException("null map key at position " + i); }
}

Try / catch

try { mapEncoding.encodeValue(...); }
catch (PrestoException e) {
    if (e.getErrorCode().getCode() == StandardErrorCode.GENERIC_INTERNAL_ERROR.toErrorCode().getCode()) {
        reportBug(e); // invariant violated by block producer
    } else { throw e; }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/23b84fe820da685a. Report an issue: GitHub.