apache/cassandra · error · InvalidRequestException
Duplicate column ' ' in CLUSTERING ORDER BY clause for table
Error message
Duplicate column '%s' in CLUSTERING ORDER BY clause for table '%s'
What it means
The CLUSTERING ORDER BY clause lists the same column more than once. The Raw builder tracks clustering order in a map keyed by column; put returning a non-null previous value means the column appeared twice, which makes the ordering ambiguous, so the statement is rejected.
Solutions
- List each clustering column exactly once in CLUSTERING ORDER BY
- Remove the duplicate entry, keeping the desired direction
- Ensure all clustering columns that need non-default order are mentioned once each
Example fix
// before CREATE TABLE t (a int, c int, PRIMARY KEY (a, c)) WITH CLUSTERING ORDER BY (c ASC, c DESC); // after CREATE TABLE t (a int, c int, PRIMARY KEY (a, c)) WITH CLUSTERING ORDER BY (c DESC);
Defensive patterns
Strategy: validation
Validate before calling
const orderCols = orderBy.map(o => o.column.toLowerCase());
if (new Set(orderCols).size !== orderCols.length) throw new Error('Duplicate column in CLUSTERING ORDER BY'); Try / catch
try { session.execute(ddl); } catch (e) { if (/in CLUSTERING ORDER BY/.test(e.message)) { /* de-duplicate the ORDER BY list and retry */ } else throw e; } Prevention
- List each clustering column once in CLUSTERING ORDER BY
- De-duplicate ordering directives when merging DDL fragments
- Cross-check ORDER BY columns against declared clustering columns
When it happens
Trigger: WITH CLUSTERING ORDER BY (c ASC, c DESC) in DDL; calling extendClusteringOrder twice for the same column identifier while building the statement raw.
Common situations: Generated DDL merging ordering directives from multiple sources; hand-written ORDER BY accidentally repeating a clustering column under different spellings that resolve to the same identifier.
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
- Missing CLUSTERING ORDER for column
- Only clustering key columns can be defined in CLUSTERING…
- The order of columns in the CLUSTERING ORDER directive must…
- ACCESS TO DATACENTERS operations not supported by…
- Aggregate ' ' already exists
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/61f8a707f162542b.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java:678
}
public void setPartitionKeyColumns(List<ColumnIdentifier> columns)
{
if (null != partitionKeyColumns)
throw ire("Multiple PRIMARY KEY specified for table '%s' (exactly one required)", name);
partitionKeyColumns = columns;
}
public void markClusteringColumn(ColumnIdentifier column)
{
clusteringColumns.add(column);
}
public void extendClusteringOrder(ColumnIdentifier column, boolean ascending)
{
if (null != clusteringOrder.put(column, ascending))
throw ire("Duplicate column '%s' in CLUSTERING ORDER BY clause for table '%s'", column, name);
}
}
/**
* Class encapsulating the properties of a column, which are its type and mask.
*/
private final static class ColumnProperties
{
public final AbstractType<?> type;
public final CQL3Type cqlType; // we keep the original CQL type for printing fully qualified user type names
@Nullable
public final ColumnMask mask;
public ColumnProperties(AbstractType<?> type, CQL3Type cqlType, @Nullable ColumnMask mask)
{
this.type = type;
this.cqlType = cqlType;View on GitHub (pinned to 88fd0f6a0e)