apache/cassandra · error · InvalidRequestException
Invalid number of arguments in call to function %s: %d requi
Error message
Invalid number of arguments in call to function %s: %d required but %d provided
What it means
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.
Source
Thrown at src/java/org/apache/cassandra/cql3/functions/FunctionResolver.java:227
* @param receiverType the receiver type
* @return {@code true} if the return type of the specified function can be assigned to the specified receiver,
* {@code false} otherwise.
*/
private static boolean matchReturnType(Function fun, AbstractType<?> receiverType)
{
return receiverType == null || fun.returnType().testAssignment(receiverType.udfType()).isAssignable();
}
// This method and matchArguments are somewhat duplicate, but this method allows us to provide more precise errors in the common
// case where there is no override for a given function. This is thus probably worth the minor code duplication.
private static void validateTypes(String keyspace,
Function fun,
List<? extends AssignmentTestable> providedArgs,
String receiverKeyspace,
String receiverTable)
{
if (providedArgs.size() != fun.argTypes().size())
throw invalidRequest("Invalid number of arguments in call to function %s: %d required but %d provided",
fun.name(), fun.argTypes().size(), providedArgs.size());
for (int i = 0; i < providedArgs.size(); i++)
{
AssignmentTestable provided = providedArgs.get(i);
// If the concrete argument is a bind variables, it can have any type.
// We'll validate the actually provided value at execution time.
if (provided == null)
continue;
ColumnSpecification expected = makeArgSpec(receiverKeyspace, receiverTable, fun, i);
if (!provided.testAssignment(keyspace, expected).isAssignable())
throw invalidRequest("Type error: %s cannot be passed as argument %d of function %s of type %s",
provided, i, fun.name(), expected.type.asCQL3Type());
}
}
View on GitHub (pinned to 88fd0f6a0e)
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
Example fix
// before: now() takes no arguments
SELECT now(1) FROM t;
// after
datastax session.execute("SELECT toTimestamp(now()) FROM t"); Defensive patterns
Strategy: validation
Validate before calling
function checkArity(fn, args, required) { if (args.length !== required) throw new Error(`${fn} requires ${required} args, got ${args.length}`); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Invalid number of arguments for function %s
- Incorrect number of arguments specified for function %s (exp
- Invalid number of arguments for function %s
- Invalid call to function %s, none of its type signatures mat
- Ambiguous call to function %s (can be matched by following s
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/c5416b59d919a987.
Report an issue: GitHub.