{"record":{"id":"3db622b4a4311ac5","repo":"apache/cassandra","slug":"truncation-is-not-supported-by-table-s","errorCode":null,"errorMessage":"Truncation is not supported by table %s","messagePattern":"Truncation is not supported by table (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/virtual/AbstractLazyVirtualTable.java","lineNumber":780,"sourceCode":"        catch (InternalTimeoutException ignore)\n        {\n            if (onTimeout != OnTimeout.BEST_EFFORT || collector.isEmpty())\n                throw new ReadTimeoutException(ONE, 0, 1, false);\n            ClientWarn.instance.warn(\"Ran out of time. Returning best effort.\");\n        }\n        return collector.finish();\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    static Object[] composePartitionKeys(DecoratedKey decoratedKey, TableMetadata metadata)\n    {\n        if (metadata.partitionKeyColumns().size() == 1)\n            return new Object[] { metadata.partitionKeyType.compose(decoratedKey.getKey()) };\n\n        ByteBuffer[] split = ((CompositeType)metadata.partitionKeyType).split(decoratedKey.getKey());\n        Object[] result = new Object[split.length];\n        for (int i = 0 ; i < split.length ; ++i)\n            result[i] = metadata.partitionKeyColumns().get(i).type.compose(split[i]);\n        return result;","sourceCodeStart":762,"sourceCodeEnd":798,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/virtual/AbstractLazyVirtualTable.java#L762-L798","documentation":"AbstractLazyVirtualTable.truncate rejects TRUNCATE statements because lazily-computed virtual tables have no persisted data to remove. Throwing InvalidRequestException makes the read-only contract explicit instead of silently no-op'ing the TRUNCATE.","triggerScenarios":"Running `TRUNCATE <virtual_table>` on any read-only virtual table, e.g. `TRUNCATE system_views.threads` or `TRUNCATE system.local`.","commonSituations":"Cleanup scripts that truncate staging/test tables applied blindly to system_views; test harnesses resetting table contents without excluding virtual tables.","solutions":["Remove TRUNCATE of virtual tables from scripts/harnesses — their contents are derived from live JVM state","Reset the underlying runtime state via nodetool or configuration instead","If the table is truly mutable, it must be an AbstractMutableLazyVirtualTable-backed table; verify which implementation backs the target table"],"exampleFix":"// before\nTRUNCATE system_views.threads;\n// after\n// virtual tables cannot be truncated; skip tables where\n// metadata().isVirtual() is true in cleanup code","handlingStrategy":"validation","validationCode":"if (metadata.isVirtual()) throw new UnsupportedOperationException(\"cannot truncate virtual table\");","typeGuard":null,"tryCatchPattern":"try { session.execute(\"TRUNCATE \" + table); } catch (InvalidRequestException e) { if (e.getMessage().startsWith(\"Truncation is not supported\")) skipTable(table); else throw e; }","preventionTips":["Exclude virtual tables from truncate/reset lists in test harnesses","Check table virtuality before emitting TRUNCATE"],"tags":["cql","virtual-table","read-only","truncate","invalid-request"],"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"}