{"record":{"id":"82a990a1eb506eca","repo":"apache/cassandra","slug":"incorrect-number-of-arguments-specified-for-functi","errorCode":null,"errorMessage":"Incorrect number of arguments specified for function %s (expected %d, found %d)","messagePattern":"Incorrect number of arguments specified for function (.+?) \\(expected (.+?), found (.+?)\\)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/FunctionCall.java","lineNumber":183,"sourceCode":"\n            ScalarFunction scalarFun = (ScalarFunction) fun;\n\n            // Functions.get() will complain if no function \"name\" type check with the provided arguments.\n            // We still have to validate that the return type matches however\n            if (!scalarFun.testAssignment(keyspace, receiver).isAssignable())\n            {\n                if (OperationFcts.isOperation(name))\n                    throw invalidRequest(\"Type error: cannot assign result of operation %s (type %s) to %s (type %s)\",\n                                         OperationFcts.getOperator(scalarFun.name()), scalarFun.returnType().asCQL3Type(),\n                                         receiver.name, receiver.type.asCQL3Type());\n\n                throw invalidRequest(\"Type error: cannot assign result of function %s (type %s) to %s (type %s)\",\n                                     scalarFun.name(), scalarFun.returnType().asCQL3Type(),\n                                     receiver.name, receiver.type.asCQL3Type());\n            }\n\n            if (fun.argTypes().size() != terms.size())\n                throw invalidRequest(\"Incorrect number of arguments specified for function %s (expected %d, found %d)\",\n                                     fun, fun.argTypes().size(), terms.size());\n\n            List<Term> parameters = new ArrayList<>(terms.size());\n            for (int i = 0; i < terms.size(); i++)\n            {\n                Term t = terms.get(i).prepare(keyspace, FunctionResolver.makeArgSpec(receiver.ksName, receiver.cfName, scalarFun, i));\n                parameters.add(t);\n            }\n\n            return new FunctionCall(scalarFun, parameters);\n        }\n\n        public AssignmentTestable.TestResult testAssignment(String keyspace, ColumnSpecification receiver)\n        {\n            // Note: Functions.get() will return null if the function doesn't exist, or throw is no function matching\n            // the arguments can be found. We may get one of those if an undefined/wrong function is used as argument\n            // of another, existing, function. In that case, we return true here because we'll throw a proper exception\n            // later with a more helpful error message that if we were to return false here.","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java#L165-L201","documentation":"After type checking, FunctionCall.Raw.prepare() verifies the resolved overload's declared argument count equals the number of supplied terms. A mismatch (possible when resolution picked an overload loosely) throws this exception stating expected vs found counts.","triggerScenarios":"Calling a function with the wrong number of arguments where resolution still found a candidate overload, e.g. `f(a, b, c)` when the matching signature takes 2 args.","commonSituations":"UDF overloads added/removed causing stale call sites; native function signatures changed between Cassandra versions; copy-pasted queries with stale argument lists.","solutions":["Match the argument count to the declared signature (check system_schema.functions)","Qualify the intended overload by passing exactly the declared parameter count/types","Recreate or add an overload with the desired arity if that call form is legitimate"],"exampleFix":"// before\nSELECT f(a, b, c) FROM t; -- f(int,int)\n// after\nSELECT f(a, b) FROM t;","handlingStrategy":"validation","validationCode":"const sig = await getFunctionSignature(keyspace, fname);\nif (sig.argTypes.length !== args.length) throw new Error(`${fname} expects ${sig.argTypes.length} args, got ${args.length}`);","typeGuard":null,"tryCatchPattern":"try { rs = session.execute(q); } catch (InvalidRequestException e) { if (e.getMessage().includes('Incorrect number of arguments')) { /* fix arg count */ } else throw e; }","preventionTips":["Generate queries from a function-signature map derived from system_schema.functions","Update call sites when UDF overloads change"],"tags":["cql","functions","arity","arguments"],"backgroundTag":"missing-required-argument","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"}