apache/cassandra · error · InvalidRequestException

Type error: %s cannot be passed as argument %d of function %

Error message

Type error: %s cannot be passed as argument %d of function %s of type %s

What it means

validateTypes checks each provided argument against the function's declared parameter type via AssignmentTestable.testAssignment. When an argument's type cannot be assigned to the expected parameter type, this InvalidRequestException is thrown, identifying which argument (0-based index), the function, and the expected CQL type.

Source

Thrown at src/java/org/apache/cassandra/cql3/functions/FunctionResolver.java:241

                                      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());
        }
    }

    private static AssignmentTestable.TestResult matchAguments(String keyspace,
                                                               Function fun,
                                                               List<? extends AssignmentTestable> providedArgs,
                                                               String receiverKeyspace,
                                                               String receiverTable)
    {
        if (providedArgs.size() != fun.argTypes().size())
            return AssignmentTestable.TestResult.NOT_ASSIGNABLE;

        // It's an exact match if all are exact match, but is not assignable as soon as any is not assignable.
        AssignmentTestable.TestResult res = AssignmentTestable.TestResult.EXACT_MATCH;
        for (int i = 0; i < providedArgs.size(); i++)
        {
            AssignmentTestable provided = providedArgs.get(i);

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Cast the offending argument to the expected type shown in the message: f((int)'5') or f((uuid)str_col)
  2. Pass a column/literal whose type actually matches the declared parameter type
  3. If the UDF signature is wrong, recreate it with CREATE OR REPLACE FUNCTION using the intended parameter types
  4. For prepared statements, verify bound-variable types match the parameter types

Example fix

// before: arg 0 is text, function expects int
SELECT myfun(name) FROM users;
// after
datastax session.execute("SELECT myfun((int)name) FROM users");
Defensive patterns

Strategy: type-guard

Validate before calling

const cqlTypeCompat = { int: ['int','varint'], text: ['text','ascii'], uuid: ['uuid','text'] };
function argMatches(providedType, expectedType) { return providedType === expectedType || (cqlTypeCompat[expectedType] || []).includes(providedType); }

Type guard

const isCqlInt = v => Number.isInteger(v) && v >= -2147483648 && v <= 2147483647;

Prevention

When it happens

Trigger: SELECT max(name, 42) where name is text and the second arg must also be text; passing a string literal to a UDF expecting int; passing an int column to a function expecting uuid; passing blob where text is declared.

Common situations: UDF signatures changed after client code was written; literals defaulted to text when a numeric type was intended; passing collection columns to scalar-only functions; schema migrations changing column types.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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