{"record":{"id":"8ce8599d84258564","repo":"prestodb/presto","slug":"invalid-function-argument-8ce859","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"map key cannot be null","messagePattern":"map key cannot be null","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/scalar/MapConstructor.java","lineNumber":167,"sourceCode":"    @UsedByGeneratedCode\n    public static Block createMap(\n            MapType mapType,\n            Type keyType,\n            Type valueType,\n            MethodHandle keyBlockEqual,\n            MethodHandle keyBlockHashCode,\n            MethodHandle keyIndeterminate,\n            SqlFunctionProperties properties,\n            Block keyBlock,\n            Block valueBlock)\n    {\n        checkCondition(keyBlock.getPositionCount() == valueBlock.getPositionCount(), INVALID_FUNCTION_ARGUMENT, \"Key and value arrays must be the same length\");\n        MapBlockBuilder mapBlockBuilder = (MapBlockBuilder) mapType.createBlockBuilder(null, keyBlock.getPositionCount() * 2);\n        BlockBuilder blockBuilder = mapBlockBuilder.beginBlockEntry();\n\n        for (int i = 0; i < keyBlock.getPositionCount(); i++) {\n            if (keyBlock.isNull(i)) {\n                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"map key cannot be null\");\n            }\n\n            if (keyType.getJavaType() == Block.class) {\n                // If it's not primitive or string, we need to look for nulls in the block.\n                Object keyObject = readNativeValue(mapType.getKeyType(), keyBlock, i);\n                try {\n                    if ((boolean) keyIndeterminate.invoke(keyObject, false)) {\n                        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"map key cannot be indeterminate: \" + mapType.getKeyType().getObjectValue(properties, keyBlock, i));\n                    }\n                }\n                catch (Throwable t) {\n                    throw internalError(t);\n                }\n            }\n\n            keyType.appendTo(keyBlock, i, blockBuilder);\n            valueType.appendTo(valueBlock, i, blockBuilder);\n        }","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/MapConstructor.java#L149-L185","documentation":"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.","triggerScenarios":"Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/MapConstructor.java:167 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace null keys, e.g. map_from_entries(filter(...)) with coalesce on the key","Filter out entries whose key is null before constructing the map","Fix upstream data so key columns are never null"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}