{"record":{"id":"c5416b59d919a987","repo":"apache/cassandra","slug":"invalid-number-of-arguments-in-call-to-function-s","errorCode":null,"errorMessage":"Invalid number of arguments in call to function %s: %d required but %d provided","messagePattern":"Invalid number of arguments in call to function (.+?): (.+?) required but (.+?) provided","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/FunctionResolver.java","lineNumber":227,"sourceCode":"     * @param receiverType the receiver type\n     * @return {@code true} if the return type of the specified function can be assigned to the specified receiver,\n     * {@code false} otherwise.\n     */\n    private static boolean matchReturnType(Function fun, AbstractType<?> receiverType)\n    {\n        return receiverType == null || fun.returnType().testAssignment(receiverType.udfType()).isAssignable();\n    }\n\n    // This method and matchArguments are somewhat duplicate, but this method allows us to provide more precise errors in the common\n    // case where there is no override for a given function. This is thus probably worth the minor code duplication.\n    private static void validateTypes(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            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","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/FunctionResolver.java#L209-L245","documentation":"validateTypes in FunctionResolver first checks arity: a resolved function's declared argument count must equal the number of provided arguments. Mismatch (too many or too few) throws this InvalidRequestException. Cassandra CQL functions do not support default or variadic arguments (except token's variadic form resolved elsewhere), so exact arity is required.","triggerScenarios":"SELECT now(1) FROM t (now takes 0 args); calling a UDF f(a,b) with f(1,2,3); forgetting an argument in uuid() or currenttimestamp()-style calls; adding arguments to native functions that take none.","commonSituations":"Copy-pasted calls edited incompletely; confusion between similar functions with different arity; UDF redefined with different parameter count than old client code sends; templated query builders appending extra params.","solutions":["Count the declared parameters of the function (see error's 'required' number) and adjust the call to pass exactly that many arguments","For UDFs, recreate with the desired signature if the arity changed: CREATE OR REPLACE FUNCTION","Remove extra placeholder parameters from prepared-statement bindings if a builder added spurious ?s","Check for confusion with a similarly named function that has the arity you're using"],"exampleFix":"// before: now() takes no arguments\nSELECT now(1) FROM t;\n// after\ndatastax session.execute(\"SELECT toTimestamp(now()) FROM t\");","handlingStrategy":"validation","validationCode":"function checkArity(fn, args, required) { if (args.length !== required) throw new Error(`${fn} requires ${required} args, got ${args.length}`); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify argument counts against Cassandra docs before shipping query templates","For UDFs, regenerate client code when the function signature changes","Review prepared-statement placeholder counts when query builders assemble calls"],"tags":["cql","function-resolution","arity"],"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"}