{"record":{"id":"c11c736b9dc82fb2","repo":"apache/cassandra","slug":"where-clause-for-materialized-view-s-cannot-con","errorCode":null,"errorMessage":"WHERE clause for materialized view '%s' cannot contain custom index expressions","messagePattern":"WHERE clause for materialized view '(.+?)' cannot contain custom index expressions","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java","lineNumber":303,"sourceCode":"                      viewName, join(\", \", transform(missingPrimaryKeyColumns, ColumnIdentifier::toString)), tableName);\n        }\n\n        Set<ColumnIdentifier> regularBaseTableColumnsInViewPrimaryKey = new HashSet<>(primaryKeyColumns);\n        transform(table.primaryKeyColumns(), c -> c.name).forEach(regularBaseTableColumnsInViewPrimaryKey::remove);\n        if (regularBaseTableColumnsInViewPrimaryKey.size() > 1)\n        {\n            throw ire(\"Cannot include more than one non-primary key column in materialized view primary key (got %s)\",\n                      join(\", \", transform(regularBaseTableColumnsInViewPrimaryKey, ColumnIdentifier::toString)));\n        }\n\n        /*\n         * Process WHERE clause\n         */\n        if (whereClause.containsTokenRelations())\n            throw new InvalidRequestException(\"Cannot use token relation when defining a materialized view\");\n\n        if (whereClause.containsCustomExpressions())\n            throw ire(\"WHERE clause for materialized view '%s' cannot contain custom index expressions\", viewName);\n\n        StatementRestrictions restrictions =\n            new StatementRestrictions(state,\n                                      StatementType.SELECT,\n                                      table,\n                                      IndexHints.NONE,\n                                      whereClause,\n                                      VariableSpecifications.empty(),\n                                      Collections.emptyList(),\n                                      null,\n                                      false,\n                                      false,\n                                      true,\n                                      true);\n\n        List<ColumnIdentifier> nonRestrictedPrimaryKeyColumns =\n            Lists.newArrayList(filter(primaryKeyColumns, name -> !restrictions.isRestricted(table.getColumn(name))));\n","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java#L285-L321","documentation":"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.","triggerScenarios":"CREATE MATERIALIZED VIEW ... WHERE col = 'SOLR-class-name(...)' or any CustomExpression in the view's WHERE clause.","commonSituations":"Users copy a SELECT query containing a custom index expression (e.g. from SOLR/other custom index integrations) into a view definition.","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."],"exampleFix":"// before\nCREATE MATERIALIZED VIEW mv AS SELECT * FROM t WHERE expr(idx_idx, 'foo bar') PRIMARY KEY (id);\n// after\nCREATE MATERIALIZED VIEW mv AS SELECT * FROM t WHERE category = 'foo' PRIMARY KEY (id);","handlingStrategy":"validation","validationCode":"// reject custom expressions in view WHERE\nif (whereClauseText.matches(\"(?s).*expr\\\\s*\\\\(.*\"))\n    throw new IllegalArgumentException(\"custom index expressions are not allowed in materialized view WHERE clauses\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only equality and IS NOT NULL relations in view WHERE clauses.","Keep custom-index filtering at read time."],"tags":["cassandra","cql","where-clause","custom-index"],"backgroundTag":"invalid-query-parameter","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"}