{"record":{"id":"491945e268702db5","repo":"apache/cassandra","slug":"cannot-include-a-virtual-table-statement-in-a-logg","errorCode":null,"errorMessage":"Cannot include a virtual table statement in a logged batch","messagePattern":"Cannot include a virtual table statement in a logged batch","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/BatchStatement.java","lineNumber":303,"sourceCode":"                hasVirtualTables = true;\n            else\n                hasRegularTables = true;\n        }\n\n        if (timestampSet && hasCounters)\n            throw new InvalidRequestException(\"Cannot provide custom timestamp for a BATCH containing counters\");\n\n        if (isCounter() && hasNonCounters)\n            throw new InvalidRequestException(\"Cannot include non-counter statement in a counter batch\");\n\n        if (hasCounters && hasNonCounters)\n            throw new InvalidRequestException(\"Counter and non-counter mutations cannot exist in the same batch\");\n\n        if (isLogged() && hasCounters)\n            throw new InvalidRequestException(\"Cannot include a counter statement in a logged batch\");\n\n        if (isLogged() && hasVirtualTables)\n            throw new InvalidRequestException(\"Cannot include a virtual table statement in a logged batch\");\n\n        if (hasVirtualTables && hasRegularTables)\n            throw new InvalidRequestException(\"Mutations for virtual and regular tables cannot exist in the same batch\");\n\n        if (hasConditions && hasVirtualTables)\n            throw new InvalidRequestException(\"Conditional BATCH statements cannot include mutations for virtual tables\");\n\n        if (hasConditions)\n        {\n            String ksName = null;\n            String cfName = null;\n            for (ModificationStatement stmt : statements)\n            {\n                if (ksName != null && (!stmt.keyspace().equals(ksName) || !stmt.table().equals(cfName)))\n                    throw new InvalidRequestException(\"Batch with conditions cannot span multiple tables: \" + stmt.source);\n                ksName = stmt.keyspace();\n                cfName = stmt.table();\n            }","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java#L285-L321","documentation":"Virtual tables (system_virtual_schema-backed, e.g. system_views) are read-only in-memory views and cannot be part of a logged batch. validate() rejects logged batches containing any mutation directed at a virtual table.","triggerScenarios":"'BEGIN BATCH UPDATE system_views.some_virtual_table ...; APPLY BATCH' — attempting any mutation on a virtual table within a logged batch.","commonSituations":"Automation scripts or monitoring tools trying to 'reset' virtual table data; copy-pasted batch templates applied against virtual tables.","solutions":["Remove the virtual table mutation from the batch — virtual tables do not accept writes at all","If a virtual-table-like write was intended, verify the keyspace/table name; you likely meant a regular table","Use the underlying regular table or the correct operational mechanism instead of mutating virtual tables"],"exampleFix":"// before\nBEGIN BATCH UPDATE system_views.settings SET value = 'x' WHERE key = 'k'; APPLY BATCH;\n// after\n-- remove the statement; virtual tables are read-only\nINSERT INTO my_settings (key, value) VALUES ('k', 'x');","handlingStrategy":"validation","validationCode":"if (statements.stream().anyMatch(s -> isVirtualTable(s.getTable())) && batchType == BatchType.LOGGED)\n    throw new IllegalArgumentException(\"Virtual tables are read-only; remove from batch\");","typeGuard":"boolean isVirtualTable(TableMetadata tm) { return tm.isVirtual(); }","tryCatchPattern":"catch (InvalidRequestException e) { if (e.getMessage().contains(\"virtual table\")) { sanitizeTableListAndRetry(); } else throw e; }","preventionTips":["Exclude system_views/system virtual keyspaces from any write-generating code","Check TableMetadata.isVirtual() before building any write against discovered tables","Never template batches over 'all tables' lists without filtering"],"tags":["cql","batch","virtual-tables","logged-batch"],"backgroundTag":"unsupported-operation","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"}