apache/cassandra · error · InvalidRequestException

Materialized views are not supported on transiently…

Error message

Materialized views are not supported on transiently replicated keyspaces

What it means

Materialized views are not permitted on keyspaces that use transient replication. MV read/write path assumptions (full replicas for view maintenance) are incompatible with transient replicas, so `CREATE MATERIALIZED VIEW` checks `keyspace.replicationStrategy.hasTransientReplicas()` and throws InvalidRequestException.

Solutions

  1. Remove transient replication: ALTER the keyspace to full replicas and run `nodetool repair -pr -full`, then create the MV.
  2. Create the materialized view in a keyspace with only full replicas.
  3. Replace the MV with application-side denormalization writing to a regular table.

Example fix

-- before
CREATE MATERIALIZED VIEW ks.v AS SELECT * FROM ks.t WHERE col IS NOT NULL PRIMARY KEY (col, pk);

-- after
ALTER KEYSPACE ks WITH replication = {'class':'NetworkTopologyStrategy','dc1':3};
-- nodetool repair -full ks
CREATE MATERIALIZED VIEW ks.v AS SELECT * FROM ks.t WHERE col IS NOT NULL PRIMARY KEY (col, pk);
Defensive patterns

Strategy: validation

Validate before calling

Row r = session.execute("SELECT replication FROM system_schema.keyspaces WHERE keyspace_name='ks'").one();
Map<String,String> repl = r.getMap("replication", String.class, String.class);
if (repl.values().stream().anyMatch(v -> v.contains("/")))
    throw new IllegalStateException("keyspace uses transient replicas; MVs unsupported");

Try / catch

try { session.execute(createMv); }
catch (InvalidQueryException e) {
  if (e.getMessage().contains("transiently replicated"))
      throw new IllegalStateException("remove transient replication (ALTER KEYSPACE + repair) before creating MV", e);
  throw e;
}

Prevention

When it happens

Trigger: `CREATE MATERIALIZED VIEW ks.view AS SELECT ... FROM ks.base WHERE ...;` where the keyspace's replication includes transient replicas (e.g. RF written as `3/1` in NetworkTopologyStrategy).

Common situations: Adopting transient replication to cut storage cost, then attempting MV-based denormalization; migration scripts that create views on all keyspaces regardless of replication settings.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/b766eca5433554de. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java:151

    @Override
    public boolean compatibleWith(ClusterMetadata metadata)
    {
        return metadata.directory.commonSerializationVersion.isAtLeast(Version.V0);
    }

    @Override
    public Keyspaces apply(ClusterMetadata metadata)
    {
        /*
         * Basic dependency validations
         */
        Keyspaces schema = metadata.schema.getKeyspaces();
        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);
        if (null == keyspace)
            throw ire("Keyspace '%s' doesn't exist", keyspaceName);

        if (keyspace.replicationStrategy.hasTransientReplicas())
            throw new InvalidRequestException("Materialized views are not supported on transiently replicated keyspaces");

        TableMetadata table = keyspace.tables.getNullable(tableName);
        if (null == table)
            throw ire("Base table '%s' doesn't exist", tableName);

        if (keyspace.hasTable(viewName))
            throw ire("Cannot create materialized view '%s' - a table with the same name already exists", viewName);

        if (keyspace.hasView(viewName))
        {
            if (ifNotExists)
                return schema;

            throw new AlreadyExistsException(keyspaceName, viewName);
        }

        /*
         * Base table validation

View on GitHub (pinned to 88fd0f6a0e)