prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

map key cannot be null

What it means

Thrown while building a map literal or map from key/value arrays (createMap): a key position in the key block is null. Presto map keys must be non-null because they are hashed and compared, so a null key aborts construction; the value block may contain nulls, the key block may not.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/MapConstructor.java:167

    @UsedByGeneratedCode
    public static Block createMap(
            MapType mapType,
            Type keyType,
            Type valueType,
            MethodHandle keyBlockEqual,
            MethodHandle keyBlockHashCode,
            MethodHandle keyIndeterminate,
            SqlFunctionProperties properties,
            Block keyBlock,
            Block valueBlock)
    {
        checkCondition(keyBlock.getPositionCount() == valueBlock.getPositionCount(), INVALID_FUNCTION_ARGUMENT, "Key and value arrays must be the same length");
        MapBlockBuilder mapBlockBuilder = (MapBlockBuilder) mapType.createBlockBuilder(null, keyBlock.getPositionCount() * 2);
        BlockBuilder blockBuilder = mapBlockBuilder.beginBlockEntry();

        for (int i = 0; i < keyBlock.getPositionCount(); i++) {
            if (keyBlock.isNull(i)) {
                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "map key cannot be null");
            }

            if (keyType.getJavaType() == Block.class) {
                // If it's not primitive or string, we need to look for nulls in the block.
                Object keyObject = readNativeValue(mapType.getKeyType(), keyBlock, i);
                try {
                    if ((boolean) keyIndeterminate.invoke(keyObject, false)) {
                        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "map key cannot be indeterminate: " + mapType.getKeyType().getObjectValue(properties, keyBlock, i));
                    }
                }
                catch (Throwable t) {
                    throw internalError(t);
                }
            }

            keyType.appendTo(keyBlock, i, blockBuilder);
            valueType.appendTo(valueBlock, i, blockBuilder);
        }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Replace null keys, e.g. map_from_entries(filter(...)) with coalesce on the key
  2. Filter out entries whose key is null before constructing the map
  3. Fix upstream data so key columns are never null
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/MapConstructor.java:167 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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