apache/cassandra · error · InvalidRequestException

No receiver table has been specified for function ${name}

Error message

No receiver table has been specified for function ${name}

What it means

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.

Source

Thrown at src/java/org/apache/cassandra/cql3/functions/TokenFct.java:87

        }
        return metadata.partitioner.getTokenFactory().toByteArray(metadata.partitioner.getToken(builder.build().serializeAsPartitionKey()));
    }

    public static void addFunctionsTo(NativeFunctions functions)
    {
        functions.add(new FunctionFactory("token")
        {
            @Override
            public NativeFunction getOrCreateFunction(List<? extends AssignmentTestable> args,
                                                      AbstractType<?> receiverType,
                                                      String receiverKeyspace,
                                                      String receiverTable)
            {
                if (receiverKeyspace == null)
                    throw new InvalidRequestException("No receiver keyspace has been specified for function " + name);

                if (receiverTable == null)
                    throw new InvalidRequestException("No receiver table has been specified for function " + name);

                TableMetadata metadata = Schema.instance.getTableMetadata(receiverKeyspace, receiverTable);
                if (metadata == null)
                    throw new InvalidRequestException(String.format("The receiver table %s.%s specified by call to " +
                                                                    "function %s hasn't been found",
                                                                    receiverKeyspace, receiverTable, name));

                return new TokenFct(metadata);
            }

            @Override
            protected NativeFunction doGetOrCreateFunction(List<AbstractType<?>> argTypes, AbstractType<?> receiverType)
            {
                throw new AssertionError("Should be unreachable");
            }
        });
    }
}

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Issue the token() call against a concrete table (FROM keyspace.table) so the receiver table is known
  2. Fully qualify the table name in the statement
  3. Avoid using token() outside of SELECT/conditions bound to a table; compute tokens offline via a script if needed

Example fix

// before
SELECT token(pk) FROM system;  // no bound receiver table
// after
SELECT token(pk) FROM my_ks.my_table;
Defensive patterns

Strategy: validation

Validate before calling

// Only emit token() inside statements bound to a concrete table:
if (!query.matches("(?is).*\\bfrom\\s+\\w+(\\.\\w+)?\\b.*"))
    throw new IllegalArgumentException("token() requires a FROM <table> clause");

Try / catch

try { session.execute(query); }
catch (InvalidRequestException e) {
  if (e.getMessage().contains("No receiver table")) { /* add FROM <ks>.<table> and retry */ }
  else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/7b747afaf67fef9d. Report an issue: GitHub.