prestodb/presto · error · PrestoException
INVALID_FUNCTION_ARGUMENT
INVALID_FUNCTION_ARGUMENT
Error message
map entry cannot be null
What it means
multimap_from_entries builds a multimap from an array of ROW(key, value) entries. If any entry in the input array is NULL, the function cannot extract a key/value pair and throws INVALID_FUNCTION_ARGUMENT, since a null map entry has no defined key.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/MultimapFromEntriesFunction.java:65
@TypeParameter("V")
@SqlType("map(K,array(V))")
@SqlNullable
public Block multimapFromEntries(
@TypeParameter("map(K,array(V))") MapType mapType,
@SqlType("array(row(K,V))") Block block)
{
Type keyType = mapType.getKeyType();
Type valueType = ((ArrayType) mapType.getValueType()).getElementType();
RowType rowType = RowType.anonymous(ImmutableList.of(keyType, valueType));
int entryCount = block.getPositionCount();
IntList[] entryIndicesList = new IntList[entryCount];
for (int i = 0; i < entryIndicesList.length; i++) {
entryIndicesList[i] = new IntArrayList();
}
TypedSet keySet = new TypedSet(keyType, entryCount, NAME);
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");
}
entryIndicesList[keySet.addAndGetPosition(rowBlock, 0)].add(i);
}
BlockBuilder multimapBlockBuilder = mapType.createBlockBuilder(null, keySet.size());
BlockBuilder singleMapWriter = multimapBlockBuilder.beginBlockEntry();
for (int i = 0; i < keySet.size(); i++) {
keyType.appendTo(rowType.getObject(block, entryIndicesList[i].getInt(0)), 0, singleMapWriter);
BlockBuilder singleArrayWriter = singleMapWriter.beginBlockEntry();
for (int entryIndex : entryIndicesList[i]) {
valueType.appendTo(rowType.getObject(block, entryIndex), 1, singleArrayWriter);
}View on GitHub (pinned to 55bb57d202)
Solutions
- Filter out NULL entries: filter(entries, e -> e IS NOT NULL) before calling the function.
- Use try_multimap_from_entries to get NULL instead of an error.
- Fix upstream queries (COALESCE or JOIN conditions) so entries are never NULL.
- Use reduce/if to skip nulls when constructing the array.
Example fix
// before SELECT multimap_from_entries(entries); // after SELECT multimap_from_entries(filter(entries, e -> e IS NOT NULL));
Defensive patterns
Strategy: validation
Validate before calling
SELECT multimap_from_entries(filter(entries, e -> e IS NOT NULL));
Try / catch
SELECT try(multimap_from_entries(entries)) AS mm;
When it happens
Trigger: Calling multimap_from_entries(ARRAY[ROW('a', 1), NULL]) — any NULL element inside the entries array triggers it.
Common situations: Arrays built from LEFT JOINs or array_agg over nullable columns contain NULL elements; JSON-derived arrays include nulls.
Related errors
- GENERIC_INTERNAL_ERROR
- INVALID_FUNCTION_ARGUMENT
- INVALID_FUNCTION_ARGUMENT
- INVALID_FUNCTION_ARGUMENT
- INVALID_CAST_ARGUMENT
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/32232ae7b0b1f36c.
Report an issue: GitHub.