apache/cassandra · error · InvalidRequestException

Incorrect number of arguments specified for function %s (exp

Error message

Incorrect number of arguments specified for function %s (expected %d, found %d)

What it means

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.

Source

Thrown at src/java/org/apache/cassandra/cql3/functions/FunctionCall.java:183

            ScalarFunction scalarFun = (ScalarFunction) fun;

            // Functions.get() will complain if no function "name" type check with the provided arguments.
            // We still have to validate that the return type matches however
            if (!scalarFun.testAssignment(keyspace, receiver).isAssignable())
            {
                if (OperationFcts.isOperation(name))
                    throw invalidRequest("Type error: cannot assign result of operation %s (type %s) to %s (type %s)",
                                         OperationFcts.getOperator(scalarFun.name()), scalarFun.returnType().asCQL3Type(),
                                         receiver.name, receiver.type.asCQL3Type());

                throw invalidRequest("Type error: cannot assign result of function %s (type %s) to %s (type %s)",
                                     scalarFun.name(), scalarFun.returnType().asCQL3Type(),
                                     receiver.name, receiver.type.asCQL3Type());
            }

            if (fun.argTypes().size() != terms.size())
                throw invalidRequest("Incorrect number of arguments specified for function %s (expected %d, found %d)",
                                     fun, fun.argTypes().size(), terms.size());

            List<Term> parameters = new ArrayList<>(terms.size());
            for (int i = 0; i < terms.size(); i++)
            {
                Term t = terms.get(i).prepare(keyspace, FunctionResolver.makeArgSpec(receiver.ksName, receiver.cfName, scalarFun, i));
                parameters.add(t);
            }

            return new FunctionCall(scalarFun, parameters);
        }

        public AssignmentTestable.TestResult testAssignment(String keyspace, ColumnSpecification receiver)
        {
            // Note: Functions.get() will return null if the function doesn't exist, or throw is no function matching
            // the arguments can be found. We may get one of those if an undefined/wrong function is used as argument
            // of another, existing, function. In that case, we return true here because we'll throw a proper exception
            // later with a more helpful error message that if we were to return false here.

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Match the argument count to the declared signature (check system_schema.functions)
  2. Qualify the intended overload by passing exactly the declared parameter count/types
  3. Recreate or add an overload with the desired arity if that call form is legitimate

Example fix

// before
SELECT f(a, b, c) FROM t; -- f(int,int)
// after
SELECT f(a, b) FROM t;
Defensive patterns

Strategy: validation

Validate before calling

const sig = await getFunctionSignature(keyspace, fname);
if (sig.argTypes.length !== args.length) throw new Error(`${fname} expects ${sig.argTypes.length} args, got ${args.length}`);

Try / catch

try { rs = session.execute(q); } catch (InvalidRequestException e) { if (e.getMessage().includes('Incorrect number of arguments')) { /* fix arg count */ } else throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: UDF overloads added/removed causing stale call sites; native function signatures changed between Cassandra versions; copy-pasted queries with stale argument lists.

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


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/82a990a1eb506eca. Report an issue: GitHub.