{"record":{"id":"61f8a707f162542b","repo":"apache/cassandra","slug":"duplicate-column-s-in-clustering-order-by-claus","errorCode":null,"errorMessage":"Duplicate column '%s' in CLUSTERING ORDER BY clause for table '%s'","messagePattern":"Duplicate column '(.+?)' in CLUSTERING ORDER BY clause for table '(.+?)'","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java","lineNumber":678,"sourceCode":"        }\n\n        public void setPartitionKeyColumns(List<ColumnIdentifier> columns)\n        {\n            if (null != partitionKeyColumns)\n                throw ire(\"Multiple PRIMARY KEY specified for table '%s' (exactly one required)\", name);\n\n            partitionKeyColumns = columns;\n        }\n\n        public void markClusteringColumn(ColumnIdentifier column)\n        {\n            clusteringColumns.add(column);\n        }\n\n        public void extendClusteringOrder(ColumnIdentifier column, boolean ascending)\n        {\n            if (null != clusteringOrder.put(column, ascending))\n                throw ire(\"Duplicate column '%s' in CLUSTERING ORDER BY clause for table '%s'\", column, name);\n        }\n    }\n\n    /**\n     * Class encapsulating the properties of a column, which are its type and mask.\n     */\n    private final static class ColumnProperties\n    {\n        public final AbstractType<?> type;\n        public final CQL3Type cqlType; // we keep the original CQL type for printing fully qualified user type names\n\n        @Nullable\n        public final ColumnMask mask;\n\n        public ColumnProperties(AbstractType<?> type, CQL3Type cqlType, @Nullable ColumnMask mask)\n        {\n            this.type = type;\n            this.cqlType = cqlType;","sourceCodeStart":660,"sourceCodeEnd":696,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java#L660-L696","documentation":"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.","triggerScenarios":"WITH CLUSTERING ORDER BY (c ASC, c DESC) in DDL; calling extendClusteringOrder twice for the same column identifier while building the statement raw.","commonSituations":"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.","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"],"exampleFix":"// before\nCREATE TABLE t (a int, c int, PRIMARY KEY (a, c)) WITH CLUSTERING ORDER BY (c ASC, c DESC);\n// after\nCREATE TABLE t (a int, c int, PRIMARY KEY (a, c)) WITH CLUSTERING ORDER BY (c DESC);","handlingStrategy":"validation","validationCode":"const orderCols = orderBy.map(o => o.column.toLowerCase());\nif (new Set(orderCols).size !== orderCols.length) throw new Error('Duplicate column in CLUSTERING ORDER BY');","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["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"],"tags":["cql","schema","clustering-order"],"backgroundTag":"schema-validation-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}