{"record":{"id":"a183969f09ee5ef2","repo":"apache/cassandra","slug":"unknown-function-s-called-in-selection-clause","errorCode":null,"errorMessage":"Unknown function %s called in selection clause","messagePattern":"Unknown function (.+?) called in selection clause","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/selection/Selectable.java","lineNumber":456,"sourceCode":"                // argument outside of check for nullness) and for backward compatibilty we want to support COUNT(1),\n                // but we actually have COUNT(x) method for every existing (simple) input types so currently COUNT(1)\n                // will throw as ambiguous (since 1 works for any type). So we have to special case COUNT.\n                if (functionName.equalsNativeFunction(FunctionName.nativeFunction(\"count\"))\n                        && preparedArgs.size() == 1\n                        && (preparedArgs.get(0) instanceof WithTerm)\n                        && (((WithTerm)preparedArgs.get(0)).rawTerm instanceof Constants.Literal))\n                {\n                    // Note that 'null' isn't a Constants.Literal\n                    name = AggregateFcts.countRowsFunction.name();\n                    preparedArgs = Collections.emptyList();\n                }\n                Function fun = FunctionResolver.get(table.keyspace, name, preparedArgs, table.keyspace, table.name, null, UserFunctions.getCurrentUserFunctions(name, table.keyspace));\n\n                if (fun == null)\n                    throw new InvalidRequestException(String.format(\"Unknown function '%s'\", functionName));\n\n                if (fun.returnType() == null)\n                    throw new InvalidRequestException(String.format(\"Unknown function %s called in selection clause\", functionName));\n\n                return new WithFunction(fun, preparedArgs);\n            }\n        }\n    }\n\n    public static class WithCast implements Selectable\n    {\n        private final CQL3Type type;\n        private final Selectable arg;\n\n        public WithCast(Selectable arg, CQL3Type type)\n        {\n            this.arg = arg;\n            this.type = type;\n        }\n\n        @Override","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/selection/Selectable.java#L438-L474","documentation":"FunctionResolver returned a function object but its return type is null, which happens for functions that cannot be used as expressions producing a value. Such functions are not valid in a selection clause and are rejected after the unknown-name check.","triggerScenarios":"Calling a null-returning function (e.g. certain internal/void-returning functions) inside SELECT fn(...) FROM t.","commonSituations":"Users try to invoke token-like, mutation-style, or otherwise non-returning native functions in the projection; these are not valid selector expressions.","solutions":["Use a function with a concrete return type in the SELECT clause","Move side-effecting or void calls out of the query entirely","Replace with an equivalent aggregate or scalar function that returns a value"],"exampleFix":"// before\nSELECT someVoidFn(x) FROM t;\n// after\nSELECT x FROM t; // drop the non-returning call","handlingStrategy":"validation","validationCode":"// only call functions with a non-null return type\nif (fn.returnType() == null) throw new IllegalArgumentException(fn + \" returns no value\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only value-returning functions in projections","Consult function docs for return types before use","Keep side-effecting calls out of SELECT clauses"],"tags":["cql","function","return-type"],"backgroundTag":"unsupported-operation","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}