apache/cassandra · error · InvalidRequestException

Invalid number of arguments for function %s

Error message

Invalid number of arguments for function %s

What it means

The native time-formatting function family (toDate/toTimestamp/toUnixTimestamp style wrappers built in FormatFcts) only supports 1-3 arguments. doGetOrCreateFunction throws invalidNumberOfArgumentsException() when the factory is asked to instantiate the function with zero arguments or more than three.

Source

Thrown at src/java/org/apache/cassandra/cql3/functions/FormatFcts.java:299

                case DAYS:
                    return 86400.0 * 1_000_000_000.0;
                default:
                    throw new IllegalArgumentException("Unsupported time unit: " + unit);
            }
        }

        public static FunctionFactory factory()
        {
            return new FunctionFactory(FUNCTION_NAME,
                                       fixed(INT, TINYINT, SMALLINT, BIGINT, VARINT, ASCII, TEXT),
                                       optional(fixed(ASCII)),
                                       optional(fixed(ASCII)))
            {
                @Override
                protected NativeFunction doGetOrCreateFunction(List<AbstractType<?>> argTypes, AbstractType<?> receiverType)
                {
                    if (argTypes.isEmpty() || argTypes.size() > 3)
                        throw invalidNumberOfArgumentsException();

                    return new FormatTimeFct(argTypes.toArray(new AbstractType<?>[0]));
                }
            };
        }
    }

    /**
     * Converts numeric value in a column to a size value of specified unit.
     * <p>
     * If the function call contains just one argument - value to convert - then it will be
     * looked at as the value is of unit 'B' and it will be converted to a value of a unit which is closest to it.
     * The result will be rounded to two decimal places.
     * E.g. If a value is (100 * 1024 + 150) then the unit will be in KiB and converted value will be 100.15.
     * <p>
     * If the function call contains two arguments - value to convert and a unit - then it will be looked at
     * as the unit of such value is 'B' and it will be converted into the value of the second (unit) argument.
     * <p>

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Pass between 1 and 3 arguments to the function, matching one of its declared signatures
  2. Check the supported signatures with DESC FUNCTIONS or the system_schema.functions table
  3. Remove extra parameters and compute them client-side instead

Example fix

// before
SELECT formatTime(ts, 'UTC', 'yyyy-MM-dd', 'extra') FROM t;
// after
SELECT formatTime(ts, 'UTC', 'yyyy-MM-dd') FROM t;
Defensive patterns

Strategy: validation

Validate before calling

if (args.length < 1 || args.length > 3) throw new Error('formatTime requires 1-3 arguments');

Try / catch

try { rs = session.execute(q); } catch (InvalidQueryException e) { if (e.getMessage().contains('Invalid number of arguments')) { /* fix arity */ } else throw e; }

Prevention

When it happens

Trigger: Calling the formatting native function with 0 arguments (no input value) or 4+ arguments, e.g. `formatTime(ts, tz, fmt, extra)`; the factory is invoked during function resolution in prepare().

Common situations: Typo'd or over-parameterized calls to native time functions in SELECT clauses; copying function signatures from other databases that accept more parameters.

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/c3e9f1aba35226f4. Report an issue: GitHub.