{"record":{"id":"32232ae7b0b1f36c","repo":"prestodb/presto","slug":"invalid-function-argument-32232a","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"map entry cannot be null","messagePattern":"map entry cannot be null","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/scalar/MultimapFromEntriesFunction.java","lineNumber":65,"sourceCode":"    @TypeParameter(\"V\")\n    @SqlType(\"map(K,array(V))\")\n    @SqlNullable\n    public Block multimapFromEntries(\n            @TypeParameter(\"map(K,array(V))\") MapType mapType,\n            @SqlType(\"array(row(K,V))\") Block block)\n    {\n        Type keyType = mapType.getKeyType();\n        Type valueType = ((ArrayType) mapType.getValueType()).getElementType();\n        RowType rowType = RowType.anonymous(ImmutableList.of(keyType, valueType));\n        int entryCount = block.getPositionCount();\n        IntList[] entryIndicesList = new IntList[entryCount];\n        for (int i = 0; i < entryIndicesList.length; i++) {\n            entryIndicesList[i] = new IntArrayList();\n        }\n        TypedSet keySet = new TypedSet(keyType, entryCount, NAME);\n        for (int i = 0; i < entryCount; i++) {\n            if (block.isNull(i)) {\n                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"map entry cannot be null\");\n            }\n            Block rowBlock = rowType.getObject(block, i);\n\n            if (rowBlock.isNull(0)) {\n                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"map key cannot be null\");\n            }\n\n            entryIndicesList[keySet.addAndGetPosition(rowBlock, 0)].add(i);\n        }\n\n        BlockBuilder multimapBlockBuilder = mapType.createBlockBuilder(null, keySet.size());\n        BlockBuilder singleMapWriter = multimapBlockBuilder.beginBlockEntry();\n        for (int i = 0; i < keySet.size(); i++) {\n            keyType.appendTo(rowType.getObject(block, entryIndicesList[i].getInt(0)), 0, singleMapWriter);\n            BlockBuilder singleArrayWriter = singleMapWriter.beginBlockEntry();\n            for (int entryIndex : entryIndicesList[i]) {\n                valueType.appendTo(rowType.getObject(block, entryIndex), 1, singleArrayWriter);\n            }","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/MultimapFromEntriesFunction.java#L47-L83","documentation":"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.","triggerScenarios":"Calling multimap_from_entries(ARRAY[ROW('a', 1), NULL]) — any NULL element inside the entries array triggers it.","commonSituations":"Arrays built from LEFT JOINs or array_agg over nullable columns contain NULL elements; JSON-derived arrays include nulls.","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."],"exampleFix":"// before\nSELECT multimap_from_entries(entries);\n// after\nSELECT multimap_from_entries(filter(entries, e -> e IS NOT NULL));","handlingStrategy":"validation","validationCode":"SELECT multimap_from_entries(filter(entries, e -> e IS NOT NULL));","typeGuard":null,"tryCatchPattern":"SELECT try(multimap_from_entries(entries)) AS mm;","preventionTips":[],"tags":["presto","sql","null","multimap","invalid-argument"],"backgroundTag":"null-map-entry","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}