{"record":{"id":"e153c498b514c793","repo":"apache/cassandra","slug":"counter-modification-statements-are-not-supported","errorCode":null,"errorMessage":"Counter modification statements are not supported","messagePattern":"Counter modification statements are not supported","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java","lineNumber":919,"sourceCode":"\n            return builder.build();\n        }\n\n        /**\n         * Prepares modification statement for writing data to SSTable\n         *\n         * @return prepared modification statement and it's bound names\n         */\n        private ModificationStatement prepareModificationStatement()\n        {\n            ClientState state = ClientState.forInternalCalls();\n            ModificationStatement preparedModificationStatement = modificationStatement.prepare(state);\n            preparedModificationStatement.validate(state);\n\n            if (preparedModificationStatement.hasConditions())\n                throw new IllegalArgumentException(\"Conditional statements are not supported\");\n            if (preparedModificationStatement.isCounter())\n                throw new IllegalArgumentException(\"Counter modification statements are not supported\");\n            if (preparedModificationStatement.getBindVariables().isEmpty())\n                throw new IllegalArgumentException(\"Provided preparedModificationStatement statement has no bind variables\");\n\n            return preparedModificationStatement;\n        }\n    }\n}\n","sourceCodeStart":901,"sourceCodeEnd":927,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java#L901-L927","documentation":"CQLSSTableWriter writes directly into SSTables without the coordinator-side counter machinery (counter shards, leader distribution), so counter modifications cannot be represented. The Builder rejects any prepared modification statement for which isCounter() is true with an IllegalArgumentException.","triggerScenarios":"Passing a counter statement such as 'UPDATE ks.t SET counter_col = counter_col + ? WHERE k = ?' (or a counter-table INSERT) to CQLSSTableWriter and calling build().","commonSituations":"Bulk-loading scripts pointed at counter tables; developers assuming bulk-load API parity with all table types.","solutions":["Do not bulk-load counter tables with CQLSSTableWriter; use normal CQL increment/decrement statements via a driver","Restructure the schema to store the value as a regular column in a non-counter table if bulk loading is essential","Split the workload: load non-counter data offline, apply counter deltas online"],"exampleFix":"// before\nString cql = \"UPDATE ks.counters SET hits = hits + ? WHERE k = ?\"; // rejected\n// after\n// use a session/driver statement instead of CQLSSTableWriter for counter tables\nsession.execute(\"UPDATE ks.counters SET hits = hits + ? WHERE k = ?\", delta, key);","handlingStrategy":"validation","validationCode":"if (schema is a counter table or statement targets counter columns)\n    throw new IllegalArgumentException(\"Use regular CQL for counter tables, not CQLSSTableWriter\");","typeGuard":null,"tryCatchPattern":"try { builder.build(); }\ncatch (IllegalArgumentException e) {\n    if (e.getMessage().equals(\"Counter modification statements are not supported\"))\n        // route through driver/LWT path instead\n}","preventionTips":["Check table metadata (counter columns) before choosing the bulk-load path","Exclude counter tables from offline loading tooling","Document counter tables as unsupported for SSTable writers"],"tags":["sstable","bulk-loading","counters","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}