{"record":{"id":"74feb2f8ed9dca84","repo":"apache/cassandra","slug":"unknown-function-s-called","errorCode":null,"errorMessage":"Unknown function %s called","messagePattern":"Unknown function (.+?) called","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/FunctionCall.java","lineNumber":162,"sourceCode":"        }\n\n        public static Raw newNegation(Term.Raw raw)\n        {\n            FunctionName name = FunctionName.nativeFunction(OperationFcts.NEGATION_FUNCTION_NAME);\n            return new Raw(name, Collections.singletonList(raw));\n        }\n\n        public static Raw newCast(Term.Raw raw, CQL3Type type)\n        {\n            FunctionName name = FunctionName.nativeFunction(CastFcts.getFunctionName(type));\n            return new Raw(name, Collections.singletonList(raw));\n        }\n\n        public Term prepare(String keyspace, ColumnSpecification receiver) throws InvalidRequestException\n        {\n            Function fun = FunctionResolver.get(keyspace, name, terms, receiver.ksName, receiver.cfName, receiver.type, UserFunctions.getCurrentUserFunctions(name, keyspace));\n            if (fun == null)\n                throw invalidRequest(\"Unknown function %s called\", name);\n            if (fun.isAggregate())\n                throw invalidRequest(\"Aggregation function are not supported in the where clause\");\n\n            ScalarFunction scalarFun = (ScalarFunction) fun;\n\n            // Functions.get() will complain if no function \"name\" type check with the provided arguments.\n            // We still have to validate that the return type matches however\n            if (!scalarFun.testAssignment(keyspace, receiver).isAssignable())\n            {\n                if (OperationFcts.isOperation(name))\n                    throw invalidRequest(\"Type error: cannot assign result of operation %s (type %s) to %s (type %s)\",\n                                         OperationFcts.getOperator(scalarFun.name()), scalarFun.returnType().asCQL3Type(),\n                                         receiver.name, receiver.type.asCQL3Type());\n\n                throw invalidRequest(\"Type error: cannot assign result of function %s (type %s) to %s (type %s)\",\n                                     scalarFun.name(), scalarFun.returnType().asCQL3Type(),\n                                     receiver.name, receiver.type.asCQL3Type());\n            }","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java#L144-L180","documentation":"FunctionCall.Raw.prepare() resolves the function name via FunctionResolver against the provided argument terms and current user functions. If the resolver returns null (no signature matches the name/args in that keyspace), the statement cannot be prepared and this InvalidRequestException is thrown.","triggerScenarios":"A function name in a SELECT/WHERE term that does not exist (or exists with an incompatible signature) in the target keyspace, e.g. `SELECT myFunc(x) FROM t` where myFunc was never CREATEd in that keyspace.","commonSituations":"Calling a user-defined function created in a different keyspace without qualifying it; typos in native function names; using an aggregate function name in a non-aggregate position; running against a cluster where the function was never deployed.","solutions":["Verify the function exists: SELECT * FROM system_schema.functions WHERE function_name = 'myfunc';","Qualify the function with its keyspace: schema.myFunc(x)","CREATE the function in the keyspace the query targets","Fix typos and check the exact argument count/types match an existing overload"],"exampleFix":"// before\nSELECT myFunc(x) FROM t;\n// after\nSELECT ks.myFunc(x) FROM t; -- or create it first:\nCREATE FUNCTION ks.myFunc(x int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return x;';","handlingStrategy":"validation","validationCode":"const known = (await session.execute(\"SELECT function_name FROM system_schema.functions WHERE keyspace_name = 'ks'\")).rows.map(r => r.function_name);\nif (!known.includes('myfunc')) throw new Error('function myfunc does not exist in ks');","typeGuard":null,"tryCatchPattern":"try { rs = session.execute(q); } catch (InvalidRequestException e) { if (e.getMessage().startsWith('Unknown function')) { /* create/qualify function */ } else throw e; }","preventionTips":["Always keyspace-qualify UDF calls","Deploy functions to all environments as part of schema migration","Validate function names against system_schema.functions at startup"],"tags":["cql","functions","udf","resolution"],"backgroundTag":"resource-not-found","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"}