apache/cassandra · error · InvalidRequestException

The token function arguments must be in the partition key…

Error message

The token function arguments must be in the partition key order: %s

What it means

Validation in ColumnsExpression.TOKEN.validateColumns: the columns given to token() were not exactly the partition key columns in partition key order. The checkTrue distinguishes a wrong order (this message) from missing partition key columns (a different message).

Solutions

  1. Reorder the token() arguments to match the partition key column order defined in the table schema.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/java/org/apache/cassandra/cql3/ColumnsExpression.java:150 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/ColumnsExpression.java:150

         * Token expression (e.g. {@code token(columnA, columnB)})
         */
        TOKEN
        {
            @Override
            protected void validateColumns(TableMetadata table, List<ColumnMetadata> columns)
            {
                if (columns.equals(table.partitionKeyColumns()))
                    return;

                // If the columns do not match the partition key columns, let's try to narrow down the problem
                checkTrue(new HashSet<>(columns).containsAll(table.partitionKeyColumns()),
                        "The token() function must be applied to all partition key components or none of them");

                checkContainsNoDuplicates(columns, "The token() function contains duplicate partition key components");

                checkContainsOnly(columns, table.partitionKeyColumns(), "The token() function must contains only partition key components");

                throw invalidRequest("The token function arguments must be in the partition key order: %s",
                                     Joiner.on(", ").join(ColumnMetadata.toIdentifiers(table.partitionKeyColumns())));
            }

            @Override
            AbstractType<?> type(TableMetadata table, List<ColumnMetadata> columns, ElementExpression element)
            {
                return table.partitioner.getTokenValidator();
            }

            @Override
            String toCQLString(List<String> columns, String element)
            {
                StringBuilder builder = new StringBuilder();
                builder.append("token(");
                Joiner.on(", ").appendTo(builder, columns);
                return builder.append(')').toString();
            }

View on GitHub (pinned to 88fd0f6a0e)