{"record":{"id":"feaba3f5fb41f886","repo":"apache/cassandra","slug":"duplicate-column-s-in-clustering-order-by-claus-feaba3","errorCode":null,"errorMessage":"Duplicate column '%s' in CLUSTERING ORDER BY clause for view '%s'","messagePattern":"Duplicate column '(.+?)' in CLUSTERING ORDER BY clause for view '(.+?)'","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java","lineNumber":492,"sourceCode":"                                           attrs,\n\n                                           ifNotExists);\n        }\n\n        public void setPartitionKeyColumns(List<ColumnIdentifier> columns)\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 view '%s'\", column, viewName);\n        }\n    }\n}\n","sourceCodeStart":474,"sourceCodeEnd":496,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java#L474-L496","documentation":"Guard in CreateViewStatement.RawStatement.extendClusteringOrder() (parser-side builder): CLUSTERING ORDER BY names the same column twice. clusteringOrder is a map keyed by column identifier, and put() returning a previous value signals the duplicate; the statement is rejected with InvalidRequestException before schema application.","triggerScenarios":"CREATE MATERIALIZED VIEW ... WITH CLUSTERING ORDER BY (col ASC, col DESC) or any duplicate column listed twice in the ORDER BY clause.","commonSituations":"Programmatic view builders appending the same column twice; hand-written DDL repeating a column with different directions; generated DDL merging two order specs.","solutions":["List each column at most once in the CLUSTERING ORDER BY clause; remove the redundant entry, since unspecified clustering columns default to ascending order."],"exampleFix":"// before\nWITH CLUSTERING ORDER BY (ts ASC, ts DESC)\n// after\nWITH CLUSTERING ORDER BY (ts ASC)","handlingStrategy":"validation","validationCode":"const cols = order.map(o => o.column); if (new Set(cols).size !== cols.length) throw new Error('Duplicate column in CLUSTERING ORDER BY');","typeGuard":null,"tryCatchPattern":"try { session.execute(ddl); } catch (e) { if (e instanceof InvalidQueryError && /Duplicate column/.test(e.message)) { /* deduplicate ORDER BY list */ } else throw e; }","preventionTips":["Deduplicate clustering columns when programmatically assembling ORDER BY clauses","Review generated DDL output before execution"],"tags":["cql","materialized-view","clustering-order","duplicate-column"],"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"}