{"record":{"id":"eae507726fe9958b","repo":"apache/cassandra","slug":"invalid-number-of-arguments-for-function-s-eae507","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/FunctionFactory.java","lineNumber":91,"sourceCode":"     *\n     * @param args the arguments in the function call for which the function is going to be built\n     * @param receiverType the expected return type of the function call for which the function is going to be built\n     * @param receiverKeyspace the name of the recevier keyspace\n     * @param receiverTable the name of the recevier table\n     * @return a function with a signature compatible with the specified function call, or {@code null} if the factory\n     * cannot create a function for the supplied arguments but there might be another factory with the same\n     * {@link #name()} able to do it.\n     */\n    @Nullable\n    public NativeFunction getOrCreateFunction(List<? extends AssignmentTestable> args,\n                                              AbstractType<?> receiverType,\n                                              String receiverKeyspace,\n                                              String receiverTable)\n    {\n        // validate the number of arguments\n        int numArgs = args.size();\n        if (numArgs < numMandatoryParameters || numArgs > numParameters)\n            throw invalidNumberOfArgumentsException();\n\n        // Do a first pass trying to infer the types of the arguments individually, without any context about the types\n        // of the other arguments. We don't do any validation during this first pass.\n        List<AbstractType<?>> types = new ArrayList<>(args.size());\n        for (int i = 0; i < args.size(); i++)\n        {\n            AssignmentTestable arg = args.get(i);\n            FunctionParameter parameter = parameters.get(i);\n            types.add(parameter.inferType(SchemaConstants.SYSTEM_KEYSPACE_NAME, arg, receiverType, null));\n        }\n\n        // Do a second pass trying to infer the types of the arguments considering the types of other inferred types.\n        // We can validate the inferred types during this second pass.\n        for (int i = 0; i < args.size(); i++)\n        {\n            AssignmentTestable arg = args.get(i);\n            FunctionParameter parameter = parameters.get(i);\n            AbstractType<?> type = parameter.inferType(SchemaConstants.SYSTEM_KEYSPACE_NAME, arg, receiverType, types);","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/FunctionFactory.java#L73-L109","documentation":"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.","triggerScenarios":"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.","commonSituations":"Calls to native functions like maxTimestamp/format functions with wrong arity; version differences where newer signatures accept more optional params than the cluster supports.","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"],"exampleFix":"// before\nSELECT toTimestamp() FROM t; -- 0 args\n// after\nSELECT toTimestamp(now()) FROM t; -- or use now()/currentTimestamp() with correct arity","handlingStrategy":"validation","validationCode":"if (args.length < mandatoryCount || args.length > maxCount) throw new Error('native function arity out of declared range');","typeGuard":null,"tryCatchPattern":"try { rs = session.execute(q); } catch (InvalidQueryException e) { if (e.getMessage().includes('Invalid number of arguments')) { /* supply mandatory args */ } else throw e; }","preventionTips":["Check DESC FUNCTIONS for mandatory vs optional parameters","Pin query templates to the cluster's Cassandra version signatures"],"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"}