{"record":{"id":"66386f65a6867636","repo":"apache/cassandra","slug":"truncation-is-not-supported-by-table-metadata","errorCode":null,"errorMessage":"Truncation is not supported by table \" + metadata","messagePattern":"Truncation is not supported by table \" \\+ metadata","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/virtual/AbstractVirtualTable.java","lineNumber":136,"sourceCode":"\n            @Override\n            public TableMetadata metadata()\n            {\n                return metadata;\n            }\n        };\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(\"Truncation is not supported by table \" + metadata);\n    }\n\n    @Override\n    public String toString()\n    {\n        return metadata().toString();\n    }\n\n    public interface DataSet\n    {\n        boolean isEmpty();\n        Partition getPartition(DecoratedKey partitionKey);\n        Iterator<Partition> getPartitions(DataRange range);\n    }\n\n    public interface Partition\n    {\n        DecoratedKey key();","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/virtual/AbstractVirtualTable.java#L118-L154","documentation":"AbstractVirtualTable's default truncate() implementation rejects TRUNCATE statements. Virtual tables hold computed, in-memory data rather than durable SSTables, so truncation has no meaning and is rejected with InvalidRequestException.","triggerScenarios":"Running 'TRUNCATE <virtual_table>' (e.g. TRUNCATE system_views.clients) against any virtual table whose class does not override truncate().","commonSituations":"Cleanup scripts that blindly truncate tables found in system_schema; test harnesses resetting system tables between runs; DBAs trying to clear large virtual table result sets.","solutions":["Do not truncate virtual tables; simply SELECT from them — data is ephemeral and recomputed on each read.","If the goal is dropping accumulated state, restart the node or use the specific admin operation that clears the underlying component.","If implementing a custom virtual table, override truncate() if clearing internal state makes sense.","Exclude tables with TableMetadata.VIRTUAL from truncation lists in scripts."],"exampleFix":"// before\nsession.execute(\"TRUNCATE system_views.clients\");\n// after\n// read-only: no truncate needed\nResultSet rs = session.execute(\"SELECT * FROM system_views.clients\");","handlingStrategy":"validation","validationCode":"if (sql.trim().toUpperCase().startsWith(\"TRUNCATE\")) { /* verify target is not a virtual table */ }","typeGuard":"boolean isTruncatable(TableMetadata m) { return !m.virtual; }","tryCatchPattern":"try { session.execute(truncate); } catch (com.datastax.driver.core.exceptions.InvalidQueryException e) { if (e.getMessage().contains(\"Truncation is not supported\")) { /* skip; virtual table */ } else throw e; }","preventionTips":["Exclude virtual tables from reset/cleanup scripts","Virtual table data is ephemeral — no truncate needed","Use TableMetadata.VIRTUAL flag to filter truncation targets"],"tags":["virtual-table","truncate","read-only","cassandra"],"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"}