{"record":{"id":"4c353b459f6c32c5","repo":"apache/cassandra","slug":"type-error-s-cannot-be-passed-as-argument-d-of","errorCode":null,"errorMessage":"Type error: %s cannot be passed as argument %d of function %s of type %s","messagePattern":"Type error: (.+?) cannot be passed as argument (.+?) of function (.+?) of type (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/FunctionResolver.java","lineNumber":241,"sourceCode":"                                      String receiverKeyspace,\n                                      String receiverTable)\n    {\n        if (providedArgs.size() != fun.argTypes().size())\n            throw invalidRequest(\"Invalid number of arguments in call to function %s: %d required but %d provided\",\n                                 fun.name(), fun.argTypes().size(), providedArgs.size());\n\n        for (int i = 0; i < providedArgs.size(); i++)\n        {\n            AssignmentTestable provided = providedArgs.get(i);\n\n            // If the concrete argument is a bind variables, it can have any type.\n            // We'll validate the actually provided value at execution time.\n            if (provided == null)\n                continue;\n\n            ColumnSpecification expected = makeArgSpec(receiverKeyspace, receiverTable, fun, i);\n            if (!provided.testAssignment(keyspace, expected).isAssignable())\n                throw invalidRequest(\"Type error: %s cannot be passed as argument %d of function %s of type %s\",\n                                     provided, i, fun.name(), expected.type.asCQL3Type());\n        }\n    }\n\n    private static AssignmentTestable.TestResult matchAguments(String keyspace,\n                                                               Function fun,\n                                                               List<? extends AssignmentTestable> providedArgs,\n                                                               String receiverKeyspace,\n                                                               String receiverTable)\n    {\n        if (providedArgs.size() != fun.argTypes().size())\n            return AssignmentTestable.TestResult.NOT_ASSIGNABLE;\n\n        // It's an exact match if all are exact match, but is not assignable as soon as any is not assignable.\n        AssignmentTestable.TestResult res = AssignmentTestable.TestResult.EXACT_MATCH;\n        for (int i = 0; i < providedArgs.size(); i++)\n        {\n            AssignmentTestable provided = providedArgs.get(i);","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/FunctionResolver.java#L223-L259","documentation":"validateTypes checks each provided argument against the function's declared parameter type via AssignmentTestable.testAssignment. When an argument's type cannot be assigned to the expected parameter type, this InvalidRequestException is thrown, identifying which argument (0-based index), the function, and the expected CQL type.","triggerScenarios":"SELECT max(name, 42) where name is text and the second arg must also be text; passing a string literal to a UDF expecting int; passing an int column to a function expecting uuid; passing blob where text is declared.","commonSituations":"UDF signatures changed after client code was written; literals defaulted to text when a numeric type was intended; passing collection columns to scalar-only functions; schema migrations changing column types.","solutions":["Cast the offending argument to the expected type shown in the message: f((int)'5') or f((uuid)str_col)","Pass a column/literal whose type actually matches the declared parameter type","If the UDF signature is wrong, recreate it with CREATE OR REPLACE FUNCTION using the intended parameter types","For prepared statements, verify bound-variable types match the parameter types"],"exampleFix":"// before: arg 0 is text, function expects int\nSELECT myfun(name) FROM users;\n// after\ndatastax session.execute(\"SELECT myfun((int)name) FROM users\");","handlingStrategy":"type-guard","validationCode":"const cqlTypeCompat = { int: ['int','varint'], text: ['text','ascii'], uuid: ['uuid','text'] };\nfunction argMatches(providedType, expectedType) { return providedType === expectedType || (cqlTypeCompat[expectedType] || []).includes(providedType); }","typeGuard":"const isCqlInt = v => Number.isInteger(v) && v >= -2147483648 && v <= 2147483647;","tryCatchPattern":null,"preventionTips":["Cast arguments to the declared parameter types of UDFs","Re-run integration tests after any UDF or column-type change","Use typed literals ((int)5, (uuid)'...') rather than bare literals in calls"],"tags":["cql","type-mismatch","function-resolution"],"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"}