{"record":{"id":"861493e2f5be2c83","repo":"prestodb/presto","slug":"invalid-function-argument-861493","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/MapFromEntriesFunction.java","lineNumber":62,"sourceCode":"    @SqlType(\"map(K,V)\")\n    @SqlNullable\n    public Block mapFromEntries(\n            @TypeParameter(\"map(K,V)\") MapType mapType,\n            SqlFunctionProperties properties,\n            @SqlType(\"array(row(K,V))\") Block block)\n    {\n        Type keyType = mapType.getKeyType();\n        Type valueType = mapType.getValueType();\n        RowType rowType = RowType.anonymous(ImmutableList.of(keyType, valueType));\n        int entryCount = block.getPositionCount();\n\n        BlockBuilder mapBlockBuilder = mapType.createBlockBuilder(null, block.getPositionCount());\n        BlockBuilder resultBuilder = mapBlockBuilder.beginBlockEntry();\n        TypedSet uniqueKeys = new TypedSet(keyType, entryCount, \"map_from_entries\");\n\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            if (!uniqueKeys.add(rowBlock, 0)) {\n                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format(\"Duplicate keys (%s) are not allowed\", keyType.getObjectValue(properties, rowBlock, 0)));\n            }\n\n            keyType.appendTo(rowBlock, 0, resultBuilder);\n            valueType.appendTo(rowBlock, 1, resultBuilder);\n        }\n\n        mapBlockBuilder.closeEntry();\n        return mapType.getObject(mapBlockBuilder, mapBlockBuilder.getPositionCount() - 1);\n    }","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/MapFromEntriesFunction.java#L44-L80","documentation":"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.","triggerScenarios":"Passing an array(row(K,V)) that contains a NULL element (the whole row is null) to map_from_entries.","commonSituations":"Array built from outer joins, unnest of sparse data, or CASE expressions that produce null rows.","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."],"exampleFix":"// before\nSELECT map_from_entries(entries) FROM t;\n// after\nSELECT map_from_entries(filter(entries, e -> e IS NOT NULL)) FROM t;","handlingStrategy":"validation","validationCode":"SELECT count(*) FROM t WHERE any_match(entries, e -> e IS NULL); -- must be 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["presto","map","null","validation"],"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"}