prestodb/presto · error · PrestoException
INVALID_FUNCTION_ARGUMENT
INVALID_FUNCTION_ARGUMENT
Error message
map entry cannot be null
What it means
Thrown by map_from_entries when an element of the input array(row(K,V)) is null. Each entry of the array must be a non-null row so its key and value can be read; a null entry (as opposed to a null value inside an entry) is rejected.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/MapFromEntriesFunction.java:62
@SqlType("map(K,V)")
@SqlNullable
public Block mapFromEntries(
@TypeParameter("map(K,V)") MapType mapType,
SqlFunctionProperties properties,
@SqlType("array(row(K,V))") Block block)
{
Type keyType = mapType.getKeyType();
Type valueType = mapType.getValueType();
RowType rowType = RowType.anonymous(ImmutableList.of(keyType, valueType));
int entryCount = block.getPositionCount();
BlockBuilder mapBlockBuilder = mapType.createBlockBuilder(null, block.getPositionCount());
BlockBuilder resultBuilder = mapBlockBuilder.beginBlockEntry();
TypedSet uniqueKeys = new TypedSet(keyType, entryCount, "map_from_entries");
for (int i = 0; i < entryCount; i++) {
if (block.isNull(i)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "map entry cannot be null");
}
Block rowBlock = rowType.getObject(block, i);
if (rowBlock.isNull(0)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "map key cannot be null");
}
if (!uniqueKeys.add(rowBlock, 0)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Duplicate keys (%s) are not allowed", keyType.getObjectValue(properties, rowBlock, 0)));
}
keyType.appendTo(rowBlock, 0, resultBuilder);
valueType.appendTo(rowBlock, 1, resultBuilder);
}
mapBlockBuilder.closeEntry();
return mapType.getObject(mapBlockBuilder, mapBlockBuilder.getPositionCount() - 1);
}View on GitHub (pinned to 55bb57d202)
Solutions
- Filter nulls first: map_from_entries(filter(entries, e -> e IS NOT NULL)).
- Fix upstream query/logic so null rows are not produced.
- Use COALESCE/if to replace null entries with default entries where semantically valid.
- Keep the call but wrap the pipeline with a fail-safe default map if nulls are expected.
Example fix
// before SELECT map_from_entries(entries) FROM t; // after SELECT map_from_entries(filter(entries, e -> e IS NOT NULL)) FROM t;
Defensive patterns
Strategy: validation
Validate before calling
SELECT count(*) FROM t WHERE any_match(entries, e -> e IS NULL); -- must be 0
Prevention
- Filter null entries before map_from_entries
- Avoid outer joins that emit null rows into entry arrays
- Add assertions in ETL that entries are non-null
When it happens
Trigger: Passing an array(row(K,V)) that contains a NULL element (the whole row is null) to map_from_entries.
Common situations: Array built from outer joins, unnest of sparse data, or CASE expressions that produce null rows.
Related errors
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/861493e2f5be2c83.
Report an issue: GitHub.