{"record":{"id":"4986aba7373647c3","repo":"apache/cassandra","slug":"truncate-is-not-supported-by-table","errorCode":null,"errorMessage":"Truncate is not supported by table ","messagePattern":"Truncate is not supported by table ","errorType":"exception","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/virtual/CollectionVirtualTableAdapter.java","lineNumber":585,"sourceCode":"        return (T) type.compose(value);\n    }\n\n    @Override\n    public TableMetadata metadata()\n    {\n        return metadata;\n    }\n\n    @Override\n    public void apply(PartitionUpdate update)\n    {\n        throw new InvalidRequestException(\"Modification is not supported by table \" + metadata);\n    }\n\n    @Override\n    public void truncate()\n    {\n        throw new InvalidRequestException(\"Truncate is not supported by table \" + metadata);\n    }\n}","sourceCodeStart":567,"sourceCodeEnd":587,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/virtual/CollectionVirtualTableAdapter.java#L567-L587","documentation":"CollectionVirtualTableAdapter.truncate rejects TRUNCATE statements against virtual tables. Virtual tables hold ephemeral runtime data derived from the node, so truncation is meaningless and unsupported; the framework throws InvalidRequestException unconditionally.","triggerScenarios":"Running `TRUNCATE <virtual_keyspace>.<virtual_table>;` (or a DROP-style data-clearing call) on any virtual table, e.g. system_views or system_settings tables.","commonSituations":"Cleanup scripts that blanket-truncate tables in system keyspaces; test fixtures resetting 'system' tables; misunderstanding that virtual tables persist data.","solutions":["Remove the TRUNCATE statement; virtual table contents cannot and need not be cleared.","If state needs resetting, restart the node or change the underlying runtime setting the table mirrors.","Verify the target keyspace is not a virtual keyspace (system_views, system_settings, etc.) before running maintenance scripts."],"exampleFix":"// before\nTRUNCATE system_views.threads;\n// after\nSELECT * FROM system_views.threads;  // read-only; no truncation possible","handlingStrategy":"validation","validationCode":"// skip TRUNCATE for virtual tables\nList<Row> virtual = session.execute(\"SELECT keyspace_name, table_name FROM system_schema.virtual_tables\").all();\nSet<String> vt = virtual.stream().map(r -> r.getString(\"keyspace_name\")+\".\"+r.getString(\"table_name\")).collect(Collectors.toSet());\nif (vt.contains(ks + \".\" + table)) return; // do not truncate","typeGuard":null,"tryCatchPattern":"try { session.execute(\"TRUNCATE \" + ks + \".\" + table); }\ncatch (com.datastax.oss.driver.api.core.servererrors.InvalidQueryException e) {\n    if (e.getMessage().contains(\"Truncate is not supported\")) { /* ignore: virtual table */ }\n    else throw e;\n}","preventionTips":["Filter virtual keyspaces out of cleanup/truncate scripts.","Never blanket-truncate system* keyspaces.","Remember virtual table data is ephemeral node state; truncation is never needed."],"tags":["cassandra","virtual-table","read-only","truncate"],"backgroundTag":"operation-not-supported","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"}