apache/cassandra · error · InvalidRequestException

Missing CLUSTERING ORDER for column %s

Error message

Missing CLUSTERING ORDER for column %s

What it means

If a table declares any CLUSTERING ORDER BY, every clustering column must appear in that directive, in primary-key order. When the directive's next entry does not match the next clustering column and that clustering column is not mentioned anywhere in the directive, Cassandra throws this 'Missing CLUSTERING ORDER' error.

Source

Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java:354

        List<ColumnIdentifier> nonClusterColumn = clusteringOrder.keySet().stream()
                                                                 .filter((id) -> !clusteringColumns.contains(id))
                                                                 .collect(Collectors.toList());
        if (!nonClusterColumn.isEmpty())
        {
            throw ire("Only clustering key columns can be defined in CLUSTERING ORDER directive: " + nonClusterColumn + " are not clustering columns");
        }

        int n = 0;
        for (ColumnIdentifier id : clusteringOrder.keySet())
        {
            ColumnIdentifier c = clusteringColumns.get(n);
            if (!id.equals(c))
            {
                if (clusteringOrder.containsKey(c))
                    throw ire("The order of columns in the CLUSTERING ORDER directive must match that of the clustering columns (%s must appear before %s)", c, id);
                else
                    throw ire("Missing CLUSTERING ORDER for column %s", c);
            }
            ++n;
        }

        // For COMPACT STORAGE, we reject any "feature" that we wouldn't be able to translate back to thrift.
        if (useCompactStorage)
        {
            validateCompactTable(clusteringColumnProperties, columns);
        }
        else
        {
            // Static columns only make sense if we have at least one clustering column. Otherwise everything is static anyway
            if (clusteringColumns.isEmpty() && !staticColumns.isEmpty())
                throw ire("Static columns are only useful (and thus allowed) if the table has at least one clustering column");
        }

        /*
         * Counter table validation

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Add the missing clustering column to the CLUSTERING ORDER BY clause with the desired ASC/DESC direction.
  2. Remove the CLUSTERING ORDER BY clause entirely (all clustering columns then default to ASC).

Example fix

// before
CREATE TABLE t (pk int, c1 int, c2 int, PRIMARY KEY (pk, c1, c2)) WITH CLUSTERING ORDER BY (c1 DESC);
// after
CREATE TABLE t (pk int, c1 int, c2 int, PRIMARY KEY (pk, c1, c2)) WITH CLUSTERING ORDER BY (c1 DESC, c2 ASC);
Defensive patterns

Strategy: validation

Validate before calling

// Every clustering column must be present once CLUSTERING ORDER BY is used:
List<String> clustering = List.of("c1", "c2");
List<String> order = List.of("c1");
if (!order.containsAll(clustering)) throw new IllegalArgumentException("Missing CLUSTERING ORDER entry for a clustering column");

Try / catch

try { session.execute(ddl); } catch (com.datastax.driver.core.exceptions.InvalidQueryException e) { if (e.getMessage().contains("Missing CLUSTERING ORDER")) { /* add missing column */ } else throw e; }

Prevention

When it happens

Trigger: CREATE TABLE ... PRIMARY KEY (pk, c1, c2) WITH CLUSTERING ORDER BY (c1 DESC) — c2 is a clustering column with no ordering entry.

Common situations: Adding a clustering column to an existing table definition without extending CLUSTERING ORDER BY; assuming unspecified clustering columns default to ASC once the directive is present.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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