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 validationView on GitHub (pinned to 88fd0f6a0e)
Solutions
- Add the missing clustering column to the CLUSTERING ORDER BY clause with the desired ASC/DESC direction.
- 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
- After adding a clustering column, update CLUSTERING ORDER BY to cover all clustering columns.
- Or omit CLUSTERING ORDER BY entirely to get all-ASC defaults.
- Review table DDL templates after primary-key changes.
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
- Only clustering key columns can be defined in CLUSTERING ORD
- The order of columns in the CLUSTERING ORDER directive must
- Static columns are only useful (and thus allowed) if the tab
- Cannot mix counter and non counter columns in the same table
- Cannot set %s on a table with counters
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/eb69e653e119fdd0.
Report an issue: GitHub.