{"record":{"id":"eaf118b575d4db77","repo":"apache/cassandra","slug":"materialized-view-s-s-doesn-t-exist","errorCode":null,"errorMessage":"Materialized view '%s.%s' doesn't exist","messagePattern":"Materialized view '(.+?)\\.(.+?)' doesn't exist","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/AlterViewStatement.java","lineNumber":82,"sourceCode":"    public boolean compatibleWith(ClusterMetadata metadata)\n    {\n        return metadata.directory.commonSerializationVersion.isAtLeast(Version.V0);\n    }\n\n    @Override\n    public Keyspaces apply(ClusterMetadata metadata)\n    {\n        Keyspaces schema = metadata.schema.getKeyspaces();\n        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);\n\n        ViewMetadata view = null == keyspace\n                          ? null\n                          : keyspace.views.getNullable(viewName);\n\n        if (null == view)\n        {\n            if (ifExists) return schema;\n            throw ire(\"Materialized view '%s.%s' doesn't exist\", keyspaceName, viewName);\n        }\n\n        attrs.validate();\n\n        // Guardrails on table properties\n        Guardrails.tableProperties.guard(attrs.updatedProperties(), attrs::removeProperty, state);\n\n        TableParams params = attrs.asAlteredTableParams(view.metadata.params);\n\n        if (params.gcGraceSeconds == 0)\n        {\n            throw ire(\"Cannot alter gc_grace_seconds of a materialized view to 0, since this \" +\n                      \"value is used to TTL undelivered updates. Setting gc_grace_seconds too \" +\n                      \"low might cause undelivered updates to expire before being replayed.\");\n        }\n\n        if (params.defaultTimeToLive > 0)\n        {","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/AlterViewStatement.java#L64-L100","documentation":"ALTER VIEW ... / ALTER MATERIALIZED VIEW ... was issued for a materialized view that does not exist in the given keyspace. AlterViewStatement.apply() looks up the view in KeyspaceMetadata.views and, when absent and no IF EXISTS clause was given, throws this InvalidRequestException. It is a schema-not-found guard before validating and applying the new view params.","triggerScenarios":"`ALTER MATERIALIZED VIEW <ks>.<view> WITH ...` where the view name is misspelled, the view was dropped, it lives in a different keyspace, or USE-keyspace resolution differs; throws unless IF EXISTS was specified.","commonSituations":"Typos in view names in migration scripts; altering a view after it was dropped by another process; assuming views live in a different keyspace than the base table; environment drift between dev/prod schemas.","solutions":["Verify the view exists with `DESCRIBE MATERIALIZED VIEWS` or query system_schema.views","Correct the keyspace/view name in the statement","Add `IF EXISTS` if the alteration should be a no-op when the view is missing","Re-create the view if it was dropped unintentionally"],"exampleFix":"// before\nALTER MATERIALIZED VIEW ks.user_by_email WITH gc_grace_seconds = 86400;\n\n// after (verify first, or tolerate absence)\nALTER MATERIALIZED VIEW ks.\"user_by_email\" WITH gc_grace_seconds = 86400;\n-- or\nALTER MATERIALIZED VIEW ks.user_by_email IF EXISTS WITH gc_grace_seconds = 86400;","handlingStrategy":"validation","validationCode":"// Verify the view exists before altering\nconst row = await session.execute(\n  \"SELECT view_name FROM system_schema.views WHERE keyspace_name = ? AND view_name = ?\",\n  [keyspace, viewName]);\nif (row.rows.length === 0 && !ifExists) throw new Error(`View ${keyspace}.${viewName} not found`);","typeGuard":"null","tryCatchPattern":"try {\n  session.execute(\"ALTER MATERIALIZED VIEW ks.v WITH gc_grace_seconds = 86400\");\n} catch (e) {\n  if (/doesn't exist/.test(e.message) && /view/i.test(e.message)) {\n    logger.warn(`view ks.v missing, skipping alteration`);\n  } else throw e;\n}","preventionTips":["Look up system_schema.views before altering","Quote mixed-case identifiers consistently","Run existence checks in the same environment as the alteration","Use IF EXISTS for idempotent migrations"],"tags":["cassandra","cql","materialized-view","not-found"],"backgroundTag":"resource-not-found","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"}