{"record":{"id":"7f898d0c43bc6de8","repo":"apache/cassandra","slug":"function-s-requires-a-map-argument-but-found-arg","errorCode":null,"errorMessage":"Function %s requires a map argument, but found argument %s of type %s","messagePattern":"Function (.+?) requires a map argument, but found argument (.+?) of type (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/FunctionParameter.java","lineNumber":341,"sourceCode":"            {\n                return \"numeric_set_or_list\";\n            }\n        };\n    }\n\n    /**\n     * @return a function parameter definition that accepts values of type {@link MapType}, independently of the types\n     * of the map keys and values.\n     */\n    static FunctionParameter anyMap()\n    {\n        return new FunctionParameter()\n        {\n            @Override\n            public void validateType(FunctionName name, AssignmentTestable arg, AbstractType<?> argType)\n            {\n                if (!argType.isUDT() && !(argType instanceof MapType))\n                    throw new InvalidRequestException(format(\"Function %s requires a map argument, \" +\n                                                             \"but found argument %s of type %s\",\n                                                             name, arg, argType.asCQL3Type()));\n            }\n\n            @Override\n            public String toString()\n            {\n                return \"map\";\n            }\n        };\n    }\n\n    /**\n     * @param type the type of the vector elements\n     * @return a function parameter definition that accepts values of type {@link VectorType} with elements of the\n     * specified {@code type} and any dimensions.\n     */\n    static FunctionParameter vector(CQL3Type type)","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/FunctionParameter.java#L323-L359","documentation":"Some native functions require their argument to be a map. FunctionParameter.validateType() checks the resolved argument type and throws this InvalidRequestException when the type is neither a MapType nor a UDT. It means the function was called with an argument of an incompatible (non-map) type.","triggerScenarios":"Calling a map-parameter function (e.g. certain format or map-oriented native functions) with a list, set, text, int, or other non-map/UDT type as the map argument.","commonSituations":"Passing a JSON string instead of a map literal; supplying a list where a map was intended; column of wrong type used as the argument after schema changes.","solutions":["Pass a map-typed argument, e.g. a map literal {'k':'v'} or a column defined as map<text,text>.","If passing a JSON string, convert it to a map via fromJson bound to a map type: fromJson('{\"k\":\"v\"}') used in an INSERT against a map column.","Alter the column or variable to map type if it was intended to be a map.","Alternatively store data as a UDT if that is accepted."],"exampleFix":"// before\nSELECT myFct(('a','b')) FROM t; -- tuple/list passed\n// after\nSELECT myFct({'a':'b'}) FROM t; -- map literal passed","handlingStrategy":"type-guard","validationCode":"AbstractType<?> t = column.getType();\nif (!(t instanceof MapType) && !t.isUDT()) throw new IllegalArgumentException(\"argument must be a map, got \" + t.asCQL3Type());","typeGuard":"boolean isMapArg(AbstractType<?> t) { return t instanceof MapType || t.isUDT(); }","tryCatchPattern":"try { session.execute(q); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"requires a map argument\")) { /* supply a map literal or typed map column */ } else throw e; }","preventionTips":["Check function signatures before calling native functions","Use map literals {'k':'v'} rather than JSON strings","Keep schema types aligned with function expectations"],"tags":["cql","type-mismatch","map"],"backgroundTag":"type-mismatch","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}