apache/cassandra · error · InvalidRequestException

Materialized view ' . ' doesn't exist

Error message

Materialized view '%s.%s' doesn't exist

What it means

Existence guard in DropViewStatement.apply(): the materialized view named in DROP MATERIALIZED VIEW cannot be resolved — the keyspace is missing or keyspace.views has no entry for viewName. Unless IF EXISTS is given, the statement fails with InvalidRequestException naming the nonexistent view.

Solutions

  1. Add IF EXISTS to make the drop idempotent; verify the view name and keyspace with DESCRIBE MATERIALIZED VIEWS; check whether the view was already dropped or is a plain table sharing the name.

Example fix

// before
DROP MATERIALIZED VIEW ks.metrics;
// after
DROP MATERIALIZED VIEW IF EXISTS ks.metrics_by_day;
Defensive patterns

Strategy: validation

Validate before calling

var exists = session.execute("SELECT view_name FROM system_schema.views WHERE keyspace_name=? AND view_name=?", ks, view).iterator().hasNext();
if (exists) session.execute("DROP MATERIALIZED VIEW IF EXISTS " + ks + "." + view);

Try / catch

try { session.execute(ddl); } catch (InvalidRequest e) { if (e.getMessage().contains("doesn't exist")) log.info("View already absent"); else throw e; }

Prevention

When it happens

Trigger: Executing DROP MATERIALIZED VIEW <ks>.<view> when keyspace.views has no entry with that name; typo in view name; script re-run after the view was already dropped; using a table name instead of the view name.

Common situations: Confusing base table names with view names; typos; running cleanup twice; environments where the view was never created.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/statements/schema/DropViewStatement.java:70

        return metadata.directory.commonSerializationVersion.isAtLeast(Version.V0);
    }

    @Override
    public Keyspaces apply(ClusterMetadata metadata)
    {
        Keyspaces schema = metadata.schema.getKeyspaces();
        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);

        ViewMetadata view = null == keyspace
                          ? null
                          : keyspace.views.getNullable(viewName);

        if (null == view)
        {
            if (ifExists)
                return schema;

            throw ire("Materialized view '%s.%s' doesn't exist", keyspaceName, viewName);
        }

        return schema.withAddedOrUpdated(keyspace.withSwapped(keyspace.views.without(viewName)));
    }

    SchemaChange schemaChangeEvent(KeyspacesDiff diff)
    {
        return new SchemaChange(Change.DROPPED, Target.TABLE, keyspaceName, viewName);
    }

    public void authorize(ClientState client)
    {
        ViewMetadata view = Schema.instance.getView(keyspaceName, viewName);
        if (null != view)
            client.ensureTablePermission(keyspaceName, view.baseTableName, Permission.ALTER);
    }

    @Override

View on GitHub (pinned to 88fd0f6a0e)