{"record":{"id":"f29df57ef08cf9ac","repo":"apache/cassandra","slug":"compact-storage-with-composite-primary-key-allows","errorCode":null,"errorMessage":"COMPACT STORAGE with composite PRIMARY KEY allows no more than one column not part of the PRIMARY KEY (got: %s)","messagePattern":"COMPACT STORAGE with composite PRIMARY KEY allows no more than one column not part of the PRIMARY KEY \\(got: (.+?)\\)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java","lineNumber":451,"sourceCode":"        boolean isDense = !clusteringColumnProperties.isEmpty();\n\n        if (columns.values().stream().anyMatch(c -> c.type.isMultiCell()))\n            throw ire(\"Non-frozen collections and UDTs are not supported with COMPACT STORAGE\");\n        if (!staticColumns.isEmpty())\n            throw ire(\"Static columns are not supported in COMPACT STORAGE tables\");\n\n        if (clusteringColumnProperties.isEmpty())\n        {\n            // It's a thrift \"static CF\" so there should be some columns definition\n            if (columns.isEmpty())\n                throw ire(\"No definition found that is not part of the PRIMARY KEY\");\n        }\n\n        if (isDense)\n        {\n            // We can have no columns (only the PK), but we can't have more than one.\n            if (columns.size() > 1)\n                throw ire(String.format(\"COMPACT STORAGE with composite PRIMARY KEY allows no more than one column not part of the PRIMARY KEY (got: %s)\", StringUtils.join(columns.keySet(), \", \")));\n        }\n        else\n        {\n            // we are in the \"static\" case, so we need at least one column defined. For non-compact however, having\n            // just the PK is fine.\n            if (columns.isEmpty())\n                throw ire(\"COMPACT STORAGE with non-composite PRIMARY KEY require one column not part of the PRIMARY KEY, none given\");\n        }\n    }\n\n    private void fixupCompactTable(List<ColumnProperties> clusteringTypes,\n                                   Map<ColumnIdentifier, ColumnProperties> columns,\n                                   boolean hasCounters,\n                                   TableMetadata.Builder builder)\n    {\n        Set<TableMetadata.Flag> flags = EnumSet.noneOf(TableMetadata.Flag.class);\n        boolean isDense = !clusteringTypes.isEmpty();\n        boolean isCompound = clusteringTypes.size() > 1;","sourceCodeStart":433,"sourceCodeEnd":469,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java#L433-L469","documentation":"A dense COMPACT STORAGE table (with clustering columns) may have at most one column outside the primary key, mirroring the Thrift dense-column-family layout where a single value column exists per row. If more than one is declared, the validator lists the offending columns in this error.","triggerScenarios":"CREATE TABLE t (pk int, c int, v1 text, v2 text, PRIMARY KEY (pk, c)) WITH COMPACT STORAGE — two non-PK columns.","commonSituations":"Modeling wide rows with multiple attributes in a legacy compact table; porting a relational multi-column layout directly to COMPACT STORAGE.","solutions":["Reduce the table to a single non-primary-key column (store extra data in one serialized/frozen value if needed).","Split data across multiple compact tables, one value column each.","Drop COMPACT STORAGE, which allows any number of regular columns."],"exampleFix":"// before\nCREATE TABLE t (pk int, c int, v1 text, v2 text, PRIMARY KEY (pk, c)) WITH COMPACT STORAGE;\n// after\nCREATE TABLE t (pk int, c int, v text, PRIMARY KEY (pk, c)) WITH COMPACT STORAGE;","handlingStrategy":"validation","validationCode":"// Dense COMPACT STORAGE tables allow at most one non-PK column:\nboolean compactStorage = true;\nboolean hasClustering = true;\nint nonPkColumnCount = 2;\nif (compactStorage && hasClustering && nonPkColumnCount > 1) throw new IllegalArgumentException(\"At most one non-PK column allowed\");","typeGuard":null,"tryCatchPattern":"try { session.execute(ddl); } catch (com.datastax.driver.core.exceptions.InvalidQueryException e) { if (e.getMessage().contains(\"allows no more than one column\")) { /* consolidate to one value column */ } else throw e; }","preventionTips":["Model wide-row compact tables with a single value column.","Encode multiple attributes into one frozen/serialized value if needed.","Use regular tables when multiple regular columns are required."],"tags":["cql","schema","compact-storage","primary-key"],"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"}