apache/cassandra · error · InvalidRequestException
COMPACT STORAGE with non-composite PRIMARY KEY require one c
Error message
COMPACT STORAGE with non-composite PRIMARY KEY require one column not part of the PRIMARY KEY, none given
What it means
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.
Source
Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java:458
if (clusteringColumnProperties.isEmpty())
{
// It's a thrift "static CF" so there should be some columns definition
if (columns.isEmpty())
throw ire("No definition found that is not part of the PRIMARY KEY");
}
if (isDense)
{
// We can have no columns (only the PK), but we can't have more than one.
if (columns.size() > 1)
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(), ", ")));
}
else
{
// we are in the "static" case, so we need at least one column defined. For non-compact however, having
// just the PK is fine.
if (columns.isEmpty())
throw ire("COMPACT STORAGE with non-composite PRIMARY KEY require one column not part of the PRIMARY KEY, none given");
}
}
private void fixupCompactTable(List<ColumnProperties> clusteringTypes,
Map<ColumnIdentifier, ColumnProperties> columns,
boolean hasCounters,
TableMetadata.Builder builder)
{
Set<TableMetadata.Flag> flags = EnumSet.noneOf(TableMetadata.Flag.class);
boolean isDense = !clusteringTypes.isEmpty();
boolean isCompound = clusteringTypes.size() > 1;
if (isDense)
flags.add(TableMetadata.Flag.DENSE);
if (isCompound)
flags.add(TableMetadata.Flag.COMPOUND);
if (hasCounters)
flags.add(TableMetadata.Flag.COUNTER);View on GitHub (pinned to 88fd0f6a0e)
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
Example fix
// before CREATE TABLE t (k int PRIMARY KEY) WITH COMPACT STORAGE; // after CREATE TABLE t (k int PRIMARY KEY, v text) WITH COMPACT STORAGE;
Defensive patterns
Strategy: validation
Validate before calling
// Validate DDL before executing
const compactNonComposite = /WITH\s+COMPACT\s+STORAGE/i.test(ddl) && !/CLUSTERING/i.test(ddl);
const colCount = ddl.match(/\(([^)]*)\)/)[1].split(',').length;
if (compactNonComposite && colCount <= 1) throw new Error('Compact table needs a non-PK column'); Try / catch
try { session.execute(ddl); } catch (e) { if (/COMPACT STORAGE/.test(e.message)) { /* add a non-key column or drop COMPACT STORAGE */ } else throw e; } Prevention
- Never define compact tables with only key columns
- Prefer dropping WITH COMPACT STORAGE for new schemas
- Add schema review checks for thrift-compat DDL
When it happens
Trigger: 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.
Common situations: Migrating thrift column families to CQL; typos or omissions leaving only the key column declared; testing minimal schema examples with COMPACT STORAGE.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Non-frozen collections and UDTs are not supported with COMPA
- Static columns are not supported in COMPACT STORAGE tables
- No definition found that is not part of the PRIMARY KEY
- COMPACT STORAGE with composite PRIMARY KEY allows no more th
- category %s not found in %s
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/2fa24fa99951295c.
Report an issue: GitHub.