{"record":{"id":"7b747afaf67fef9d","repo":"apache/cassandra","slug":"no-receiver-table-has-been-specified-for-function","errorCode":null,"errorMessage":"No receiver table has been specified for function ${name}","messagePattern":"No receiver table has been specified for function (.+?)","errorType":"exception","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/TokenFct.java","lineNumber":87,"sourceCode":"        }\n        return metadata.partitioner.getTokenFactory().toByteArray(metadata.partitioner.getToken(builder.build().serializeAsPartitionKey()));\n    }\n\n    public static void addFunctionsTo(NativeFunctions functions)\n    {\n        functions.add(new FunctionFactory(\"token\")\n        {\n            @Override\n            public NativeFunction getOrCreateFunction(List<? extends AssignmentTestable> args,\n                                                      AbstractType<?> receiverType,\n                                                      String receiverKeyspace,\n                                                      String receiverTable)\n            {\n                if (receiverKeyspace == null)\n                    throw new InvalidRequestException(\"No receiver keyspace has been specified for function \" + name);\n\n                if (receiverTable == null)\n                    throw new InvalidRequestException(\"No receiver table has been specified for function \" + name);\n\n                TableMetadata metadata = Schema.instance.getTableMetadata(receiverKeyspace, receiverTable);\n                if (metadata == null)\n                    throw new InvalidRequestException(String.format(\"The receiver table %s.%s specified by call to \" +\n                                                                    \"function %s hasn't been found\",\n                                                                    receiverKeyspace, receiverTable, name));\n\n                return new TokenFct(metadata);\n            }\n\n            @Override\n            protected NativeFunction doGetOrCreateFunction(List<AbstractType<?>> argTypes, AbstractType<?> receiverType)\n            {\n                throw new AssertionError(\"Should be unreachable\");\n            }\n        });\n    }\n}","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/TokenFct.java#L69-L105","documentation":"token() must be resolved against the partition key of a specific table, so the receiver table name is required. When the receiver table is null at resolution time, this InvalidRequestException is thrown.","triggerScenarios":"Calling token() where the statement resolution supplies a keyspace but no table — e.g. non-table-bound query contexts or programmatically built selectors with a null receiver table.","commonSituations":"Ad-hoc tooling and query builders constructing token() calls detached from a table; misuse of token() in contexts like aggregates where the table is not bound.","solutions":["Issue the token() call against a concrete table (FROM keyspace.table) so the receiver table is known","Fully qualify the table name in the statement","Avoid using token() outside of SELECT/conditions bound to a table; compute tokens offline via a script if needed"],"exampleFix":"// before\nSELECT token(pk) FROM system;  // no bound receiver table\n// after\nSELECT token(pk) FROM my_ks.my_table;","handlingStrategy":"validation","validationCode":"// Only emit token() inside statements bound to a concrete table:\nif (!query.matches(\"(?is).*\\\\bfrom\\\\s+\\\\w+(\\\\.\\\\w+)?\\\\b.*\"))\n    throw new IllegalArgumentException(\"token() requires a FROM <table> clause\");","typeGuard":null,"tryCatchPattern":"try { session.execute(query); }\ncatch (InvalidRequestException e) {\n  if (e.getMessage().contains(\"No receiver table\")) { /* add FROM <ks>.<table> and retry */ }\n  else throw e;\n}","preventionTips":["Always use token() in a SELECT ... FROM keyspace.table statement","Avoid token() in tableless contexts; compute tokens client-side instead"],"tags":["cql","function","token","table"],"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"}