{"record":{"id":"eb69e653e119fdd0","repo":"apache/cassandra","slug":"missing-clustering-order-for-column-s","errorCode":null,"errorMessage":"Missing CLUSTERING ORDER for column %s","messagePattern":"Missing CLUSTERING ORDER for column (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java","lineNumber":354,"sourceCode":"\n        List<ColumnIdentifier> nonClusterColumn = clusteringOrder.keySet().stream()\n                                                                 .filter((id) -> !clusteringColumns.contains(id))\n                                                                 .collect(Collectors.toList());\n        if (!nonClusterColumn.isEmpty())\n        {\n            throw ire(\"Only clustering key columns can be defined in CLUSTERING ORDER directive: \" + nonClusterColumn + \" are not clustering columns\");\n        }\n\n        int n = 0;\n        for (ColumnIdentifier id : clusteringOrder.keySet())\n        {\n            ColumnIdentifier c = clusteringColumns.get(n);\n            if (!id.equals(c))\n            {\n                if (clusteringOrder.containsKey(c))\n                    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);\n                else\n                    throw ire(\"Missing CLUSTERING ORDER for column %s\", c);\n            }\n            ++n;\n        }\n\n        // For COMPACT STORAGE, we reject any \"feature\" that we wouldn't be able to translate back to thrift.\n        if (useCompactStorage)\n        {\n            validateCompactTable(clusteringColumnProperties, columns);\n        }\n        else\n        {\n            // Static columns only make sense if we have at least one clustering column. Otherwise everything is static anyway\n            if (clusteringColumns.isEmpty() && !staticColumns.isEmpty())\n                throw ire(\"Static columns are only useful (and thus allowed) if the table has at least one clustering column\");\n        }\n\n        /*\n         * Counter table validation","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java#L336-L372","documentation":"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.","triggerScenarios":"CREATE TABLE ... PRIMARY KEY (pk, c1, c2) WITH CLUSTERING ORDER BY (c1 DESC) — c2 is a clustering column with no ordering entry.","commonSituations":"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.","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)."],"exampleFix":"// before\nCREATE TABLE t (pk int, c1 int, c2 int, PRIMARY KEY (pk, c1, c2)) WITH CLUSTERING ORDER BY (c1 DESC);\n// after\nCREATE TABLE t (pk int, c1 int, c2 int, PRIMARY KEY (pk, c1, c2)) WITH CLUSTERING ORDER BY (c1 DESC, c2 ASC);","handlingStrategy":"validation","validationCode":"// Every clustering column must be present once CLUSTERING ORDER BY is used:\nList<String> clustering = List.of(\"c1\", \"c2\");\nList<String> order = List.of(\"c1\");\nif (!order.containsAll(clustering)) throw new IllegalArgumentException(\"Missing CLUSTERING ORDER entry for a clustering column\");","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["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."],"tags":["cql","schema","create-table","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-14T16:17:12.679Z"}