apache/cassandra · error · InvalidRequestException
Primary key columns %s must be restricted with 'IS NOT NULL'
Error message
Primary key columns %s must be restricted with 'IS NOT NULL' or otherwise
What it means
Every primary key column of a materialized view must be explicitly restricted in the WHERE clause - either bound to a constant or restricted with IS NOT NULL. Unrestricted view key columns would be null-able and cannot form valid view row identities.
Source
Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java:324
new StatementRestrictions(state,
StatementType.SELECT,
table,
IndexHints.NONE,
whereClause,
VariableSpecifications.empty(),
Collections.emptyList(),
null,
false,
false,
true,
true);
List<ColumnIdentifier> nonRestrictedPrimaryKeyColumns =
Lists.newArrayList(filter(primaryKeyColumns, name -> !restrictions.isRestricted(table.getColumn(name))));
if (!nonRestrictedPrimaryKeyColumns.isEmpty())
{
throw ire("Primary key columns %s must be restricted with 'IS NOT NULL' or otherwise",
join(", ", transform(nonRestrictedPrimaryKeyColumns, ColumnIdentifier::toString)));
}
// See CASSANDRA-13798
Set<ColumnMetadata> restrictedNonPrimaryKeyColumns = restrictions.nonPKRestrictedColumns(false);
if (!restrictedNonPrimaryKeyColumns.isEmpty() && !MV_ALLOW_FILTERING_NONKEY_COLUMNS_UNSAFE.getBoolean())
{
throw ire("Non-primary key columns can only be restricted with 'IS NOT NULL' (got: %s restricted illegally)",
join(",", transform(restrictedNonPrimaryKeyColumns, ColumnMetadata::toString)));
}
/*
* Validate WITH params
*/
attrs.validate();
if (attrs.hasOption(TableParams.Option.DEFAULT_TIME_TO_LIVE)View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Add 'col IS NOT NULL' for each unrestricted primary key column in the WHERE clause.
- Restrict the column with an equality condition instead (e.g. b = 'x').
- Remove the column from the view primary key if it should not be restricted.
Example fix
// before CREATE MATERIALIZED VIEW mv AS SELECT a, b, c FROM t WHERE a IS NOT NULL PRIMARY KEY (a, b, c); // after CREATE MATERIALIZED VIEW mv AS SELECT a, b, c FROM t WHERE a IS NOT NULL AND b IS NOT NULL AND c IS NOT NULL PRIMARY KEY (a, b, c);
Defensive patterns
Strategy: validation
Validate before calling
List<String> unrestricted = viewPkColumns.stream()
.filter(c -> !whereRestricts(c))
.collect(toList());
if (!unrestricted.isEmpty())
throw new IllegalArgumentException("add IS NOT NULL for: " + unrestricted); Prevention
- After writing the view PRIMARY KEY, verify each column appears in WHERE (IS NOT NULL or equality).
- Regenerate the WHERE clause whenever the view key changes.
When it happens
Trigger: CREATE MATERIALIZED VIEW ... PRIMARY KEY (a, b) WHERE a IS NOT NULL, omitting a restriction (e.g. IS NOT NULL or equality) for column b.
Common situations: Users forget one of several key columns when writing the view WHERE clause, especially after adding columns to the PRIMARY KEY clause.
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
- Load CIDR groups cache operation not supported by %s
- 'Get CIDR groups for IP' operation not supported by %s
- ACCESS TO DATACENTERS operations not supported by AllowAllNe
- Remote configuration of auth caches is disabled
- Cannot use token relation when defining a materialized view
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/14e8e4f1ac895c21.
Report an issue: GitHub.