apache/cassandra · error · InvalidRequestException
WHERE clause for materialized view '%s' cannot contain custo
Error message
WHERE clause for materialized view '%s' cannot contain custom index expressions
What it means
Materialized view WHERE clauses cannot use custom index expressions (e.g. ALLOW FILTERING-style sigh expressions or custom index queries). Custom index expressions require an index at read time and cannot be evaluated when maintaining a view incrementally.
Source
Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java:303
viewName, join(", ", transform(missingPrimaryKeyColumns, ColumnIdentifier::toString)), tableName);
}
Set<ColumnIdentifier> regularBaseTableColumnsInViewPrimaryKey = new HashSet<>(primaryKeyColumns);
transform(table.primaryKeyColumns(), c -> c.name).forEach(regularBaseTableColumnsInViewPrimaryKey::remove);
if (regularBaseTableColumnsInViewPrimaryKey.size() > 1)
{
throw ire("Cannot include more than one non-primary key column in materialized view primary key (got %s)",
join(", ", transform(regularBaseTableColumnsInViewPrimaryKey, ColumnIdentifier::toString)));
}
/*
* Process WHERE clause
*/
if (whereClause.containsTokenRelations())
throw new InvalidRequestException("Cannot use token relation when defining a materialized view");
if (whereClause.containsCustomExpressions())
throw ire("WHERE clause for materialized view '%s' cannot contain custom index expressions", viewName);
StatementRestrictions restrictions =
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))));
View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Replace the custom expression with plain relations (equality/IS NOT NULL) on base columns.
- Move custom-expression filtering to read time against a view or table that already satisfies the other view conditions.
- Drop the custom expression condition from the view WHERE clause.
Example fix
// before CREATE MATERIALIZED VIEW mv AS SELECT * FROM t WHERE expr(idx_idx, 'foo bar') PRIMARY KEY (id); // after CREATE MATERIALIZED VIEW mv AS SELECT * FROM t WHERE category = 'foo' PRIMARY KEY (id);
Defensive patterns
Strategy: validation
Validate before calling
// reject custom expressions in view WHERE
if (whereClauseText.matches("(?s).*expr\\s*\\(.*"))
throw new IllegalArgumentException("custom index expressions are not allowed in materialized view WHERE clauses"); Prevention
- Use only equality and IS NOT NULL relations in view WHERE clauses.
- Keep custom-index filtering at read time.
When it happens
Trigger: CREATE MATERIALIZED VIEW ... WHERE col = 'SOLR-class-name(...)' or any CustomExpression in the view's WHERE clause.
Common situations: Users copy a SELECT query containing a custom index expression (e.g. from SOLR/other custom index integrations) into a view definition.
Understand the failure class
Background: "Invalid query parameter" / "Failed to parse value of ...": fixing bad query string parameters across APIs — this error's family across 36 libraries.
Related errors
- IndexRestrictions.MULTIPLE_EXPRESSIONS
- Custom index expressions cannot be used in WHERE clauses for
- Primary key columns %s must be restricted with 'IS NOT NULL'
- category %s not found in %s
- GRANT operation is not supported by AllowAllAuthorizer
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/c11c736b9dc82fb2.
Report an issue: GitHub.