apache/cassandra · error · InvalidRequestException
COMPACT STORAGE with composite PRIMARY KEY allows no more th
Error message
COMPACT STORAGE with composite PRIMARY KEY allows no more than one column not part of the PRIMARY KEY (got: %s)
What it means
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.
Source
Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java:451
boolean isDense = !clusteringColumnProperties.isEmpty();
if (columns.values().stream().anyMatch(c -> c.type.isMultiCell()))
throw ire("Non-frozen collections and UDTs are not supported with COMPACT STORAGE");
if (!staticColumns.isEmpty())
throw ire("Static columns are not supported in COMPACT STORAGE tables");
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;View on GitHub (pinned to 88fd0f6a0e)
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.
Example fix
// before CREATE TABLE t (pk int, c int, v1 text, v2 text, PRIMARY KEY (pk, c)) WITH COMPACT STORAGE; // after CREATE TABLE t (pk int, c int, v text, PRIMARY KEY (pk, c)) WITH COMPACT STORAGE;
Defensive patterns
Strategy: validation
Validate before calling
// Dense COMPACT STORAGE tables allow at most one non-PK column:
boolean compactStorage = true;
boolean hasClustering = true;
int nonPkColumnCount = 2;
if (compactStorage && hasClustering && nonPkColumnCount > 1) throw new IllegalArgumentException("At most one non-PK column allowed"); Try / catch
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; } Prevention
- 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.
When it happens
Trigger: CREATE TABLE t (pk int, c int, v1 text, v2 text, PRIMARY KEY (pk, c)) WITH COMPACT STORAGE — two non-PK columns.
Common situations: Modeling wide rows with multiple attributes in a legacy compact table; porting a relational multi-column layout directly to 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
- %s constraint can not be specified on a %s key column '%s'
- Cannot drop PRIMARY KEY column %s
- Unknown column '%s' referenced in PRIMARY KEY for table '%s'
- Duplicate column '%s' in PRIMARY KEY clause for table '%s'
- Static column '%s' cannot be part of the PRIMARY KEY
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/f29df57ef08cf9ac.
Report an issue: GitHub.