{"record":{"id":"c3e9f1aba35226f4","repo":"apache/cassandra","slug":"invalid-number-of-arguments-for-function-s","errorCode":null,"errorMessage":"Invalid number of arguments for function %s","messagePattern":"Invalid number of arguments for function (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/FormatFcts.java","lineNumber":299,"sourceCode":"                case DAYS:\n                    return 86400.0 * 1_000_000_000.0;\n                default:\n                    throw new IllegalArgumentException(\"Unsupported time unit: \" + unit);\n            }\n        }\n\n        public static FunctionFactory factory()\n        {\n            return new FunctionFactory(FUNCTION_NAME,\n                                       fixed(INT, TINYINT, SMALLINT, BIGINT, VARINT, ASCII, TEXT),\n                                       optional(fixed(ASCII)),\n                                       optional(fixed(ASCII)))\n            {\n                @Override\n                protected NativeFunction doGetOrCreateFunction(List<AbstractType<?>> argTypes, AbstractType<?> receiverType)\n                {\n                    if (argTypes.isEmpty() || argTypes.size() > 3)\n                        throw invalidNumberOfArgumentsException();\n\n                    return new FormatTimeFct(argTypes.toArray(new AbstractType<?>[0]));\n                }\n            };\n        }\n    }\n\n    /**\n     * Converts numeric value in a column to a size value of specified unit.\n     * <p>\n     * If the function call contains just one argument - value to convert - then it will be\n     * 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.\n     * The result will be rounded to two decimal places.\n     * E.g. If a value is (100 * 1024 + 150) then the unit will be in KiB and converted value will be 100.15.\n     * <p>\n     * If the function call contains two arguments - value to convert and a unit - then it will be looked at\n     * as the unit of such value is 'B' and it will be converted into the value of the second (unit) argument.\n     * <p>","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/FormatFcts.java#L281-L317","documentation":"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.","triggerScenarios":"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().","commonSituations":"Typo'd or over-parameterized calls to native time functions in SELECT clauses; copying function signatures from other databases that accept more parameters.","solutions":["Pass between 1 and 3 arguments to the function, matching one of its declared signatures","Check the supported signatures with DESC FUNCTIONS or the system_schema.functions table","Remove extra parameters and compute them client-side instead"],"exampleFix":"// before\nSELECT formatTime(ts, 'UTC', 'yyyy-MM-dd', 'extra') FROM t;\n// after\nSELECT formatTime(ts, 'UTC', 'yyyy-MM-dd') FROM t;","handlingStrategy":"validation","validationCode":"if (args.length < 1 || args.length > 3) throw new Error('formatTime requires 1-3 arguments');","typeGuard":null,"tryCatchPattern":"try { rs = session.execute(q); } catch (InvalidQueryException e) { if (e.getMessage().contains('Invalid number of arguments')) { /* fix arity */ } else throw e; }","preventionTips":["Check function signatures with DESC FUNCTIONS before calling","Keep native function calls to documented arities only"],"tags":["cql","functions","arity","native-functions"],"backgroundTag":"missing-required-argument","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}