{"record":{"id":"2fa24fa99951295c","repo":"apache/cassandra","slug":"compact-storage-with-non-composite-primary-key-req","errorCode":null,"errorMessage":"COMPACT STORAGE with non-composite PRIMARY KEY require one column not part of the PRIMARY KEY, none given","messagePattern":"COMPACT STORAGE with non-composite PRIMARY KEY require one column not part of the PRIMARY KEY, none given","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java","lineNumber":458,"sourceCode":"        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;\n\n        if (isDense)\n            flags.add(TableMetadata.Flag.DENSE);\n        if (isCompound)\n            flags.add(TableMetadata.Flag.COMPOUND);\n        if (hasCounters)\n            flags.add(TableMetadata.Flag.COUNTER);","sourceCodeStart":440,"sourceCodeEnd":476,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java#L440-L476","documentation":"Cassandra throws this when a table is declared WITH COMPACT STORAGE and has a non-composite (single-column, non-CLUSTERING) PRIMARY KEY, but no non-key columns were defined. Compact tables map rows directly to thrift-era storage, so at least one value column outside the PRIMARY KEY must exist. It is thrown during table validation in CreateTableStatement.validateCompactTable.","triggerScenarios":"Running CREATE TABLE ... WITH COMPACT STORAGE where the PRIMARY KEY is a single partition key (non-composite) and the column list contains only the key column(s), e.g. CREATE TABLE t (k int PRIMARY KEY) WITH COMPACT STORAGE.","commonSituations":"Migrating thrift column families to CQL; typos or omissions leaving only the key column declared; testing minimal schema examples with COMPACT STORAGE.","solutions":["Add at least one regular (non-PARTITION-KEY, non-CLUSTERING) column to the table definition, e.g. value text","Remove WITH COMPACT STORAGE if thrift compatibility is not required","Use a composite PRIMARY KEY (partition key plus clustering column(s)) if a key-only compact table is truly needed"],"exampleFix":"// before\nCREATE TABLE t (k int PRIMARY KEY) WITH COMPACT STORAGE;\n// after\nCREATE TABLE t (k int PRIMARY KEY, v text) WITH COMPACT STORAGE;","handlingStrategy":"validation","validationCode":"// Validate DDL before executing\nconst compactNonComposite = /WITH\\s+COMPACT\\s+STORAGE/i.test(ddl) && !/CLUSTERING/i.test(ddl);\nconst colCount = ddl.match(/\\(([^)]*)\\)/)[1].split(',').length;\nif (compactNonComposite && colCount <= 1) throw new Error('Compact table needs a non-PK column');","typeGuard":null,"tryCatchPattern":"try { session.execute(ddl); } catch (e) { if (/COMPACT STORAGE/.test(e.message)) { /* add a non-key column or drop COMPACT STORAGE */ } else throw e; }","preventionTips":["Never define compact tables with only key columns","Prefer dropping WITH COMPACT STORAGE for new schemas","Add schema review checks for thrift-compat DDL"],"tags":["cql","schema","compact-storage"],"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"}