prestodb/presto · error · NotSupportedException

map key cannot be null or contain nulls

Error message

map key cannot be null or contain nulls

What it means

In buildHashTableStrict, the duplicate-key probe returns null when the key block (or a nested row key) contains a null, meaning duplicate detection cannot be performed. The method converts that into NotSupportedException 'map key cannot be null or contain nulls' because strict map building requires every key to be hashable and comparable.

Source

Thrown at presto-common/src/main/java/com/facebook/presto/common/block/MapBlockBuilder.java:587

                if (outputHashTable[hashTableOffset + hash] == -1) {
                    outputHashTable[hashTableOffset + hash] = i;
                    break;
                }

                Boolean isDuplicateKey;
                try {
                    // assuming maps with indeterminate keys are not supported
                    isDuplicateKey = (Boolean) keyBlockEquals.invokeExact(keyBlock, keyOffset + i, keyBlock, keyOffset + outputHashTable[hashTableOffset + hash]);
                }
                catch (RuntimeException e) {
                    throw e;
                }
                catch (Throwable throwable) {
                    throw new RuntimeException(throwable);
                }

                if (isDuplicateKey == null) {
                    throw new NotSupportedException("map key cannot be null or contain nulls");
                }

                if (isDuplicateKey) {
                    throw new DuplicateMapKeyException(keyBlock, keyOffset + i);
                }

                hash++;
                if (hash == hashTableSize) {
                    hash = 0;
                }
            }
        }
    }

    private static int getHashPosition(Block keyBlock, int position, MethodHandle keyBlockHashCode, int hashTableSize)
    {
        if (keyBlock.isNull(position)) {
            throw new IllegalArgumentException("map keys cannot be null");

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Ensure all key values are non-null before building the map
  2. Filter out null keys / entries upstream (e.g. in the function producing entries)
  3. Use the non-strict entry-close path only if null keys are genuinely impossible to rule out

Example fix

// before
builder.entryIsNull / builder.closeEntryStrict(); // key NULL present
// after
checkState(!keyBlock.isNull(keyPosition), "map key cannot be null");
builder.closeEntryStrict();
Defensive patterns

Strategy: validation

Validate before calling

for (int i = 0; i < entries.getPositionCount(); i += 2) {
    if (entries.isNull(i)) {
        entries = dropNullKeyEntries(entries);
    }
}

Try / catch

try {
    builder.closeEntryStrict();
} catch (NotSupportedException e) {
    // reject input: null or partially-null map key
}

Prevention

When it happens

Trigger: Closing an entry with closeEntryStrict on a MapBlockBuilder whose key block contains null at some position (or a ROW-typed key block containing nulls), causing isDuplicateKey == null.

Common situations: Building maps with map_from_entries or similar functions where one entry's key evaluated to NULL; constructing ROW keys where an inner field is NULL.

Related errors


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