apache/cassandra · error · InvalidRequestException
Invalid number of arguments for function %s
Error message
Invalid number of arguments for function %s
What it means
FunctionFactory.getOrCreateFunction() validates argument count against the factory's declared mandatory/optional parameter counts before inferring types. If numArgs is below the number of mandatory parameters or above the total parameter count, invalidNumberOfArgumentsException() is thrown.
Source
Thrown at src/java/org/apache/cassandra/cql3/functions/FunctionFactory.java:91
*
* @param args the arguments in the function call for which the function is going to be built
* @param receiverType the expected return type of the function call for which the function is going to be built
* @param receiverKeyspace the name of the recevier keyspace
* @param receiverTable the name of the recevier table
* @return a function with a signature compatible with the specified function call, or {@code null} if the factory
* cannot create a function for the supplied arguments but there might be another factory with the same
* {@link #name()} able to do it.
*/
@Nullable
public NativeFunction getOrCreateFunction(List<? extends AssignmentTestable> args,
AbstractType<?> receiverType,
String receiverKeyspace,
String receiverTable)
{
// validate the number of arguments
int numArgs = args.size();
if (numArgs < numMandatoryParameters || numArgs > numParameters)
throw invalidNumberOfArgumentsException();
// Do a first pass trying to infer the types of the arguments individually, without any context about the types
// of the other arguments. We don't do any validation during this first pass.
List<AbstractType<?>> types = new ArrayList<>(args.size());
for (int i = 0; i < args.size(); i++)
{
AssignmentTestable arg = args.get(i);
FunctionParameter parameter = parameters.get(i);
types.add(parameter.inferType(SchemaConstants.SYSTEM_KEYSPACE_NAME, arg, receiverType, null));
}
// Do a second pass trying to infer the types of the arguments considering the types of other inferred types.
// We can validate the inferred types during this second pass.
for (int i = 0; i < args.size(); i++)
{
AssignmentTestable arg = args.get(i);
FunctionParameter parameter = parameters.get(i);
AbstractType<?> type = parameter.inferType(SchemaConstants.SYSTEM_KEYSPACE_NAME, arg, receiverType, types);View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Supply at least the mandatory arguments and at most the maximum supported (check DESC FUNCTIONS for signatures)
- Remove extraneous arguments and hardcode them client-side
- Upgrade/downgrade awareness: confirm the target Cassandra version's supported overloads
Example fix
// before SELECT toTimestamp() FROM t; -- 0 args // after SELECT toTimestamp(now()) FROM t; -- or use now()/currentTimestamp() with correct arity
Defensive patterns
Strategy: validation
Validate before calling
if (args.length < mandatoryCount || args.length > maxCount) throw new Error('native function arity out of declared range'); Try / catch
try { rs = session.execute(q); } catch (InvalidQueryException e) { if (e.getMessage().includes('Invalid number of arguments')) { /* supply mandatory args */ } else throw e; } Prevention
- Check DESC FUNCTIONS for mandatory vs optional parameters
- Pin query templates to the cluster's Cassandra version signatures
When it happens
Trigger: Any native function built on FunctionFactory called with fewer mandatory args than required (e.g. zero-arg call) or more than max, e.g. `currentTimestamp(1, 2, 3, 4)` or a formatter called with no arguments.
Common situations: Calls to native functions like maxTimestamp/format functions with wrong arity; version differences where newer signatures accept more optional params than the cluster supports.
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
- Unknown function %s called
- Aggregation function are not supported in the where clause
- Type error: cannot assign result of operation %s (type %s) t
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/eae507726fe9958b.
Report an issue: GitHub.