{"record":{"id":"04194878e15763ad","repo":"apache/cassandra","slug":"counter-update-statements-are-not-supported","errorCode":null,"errorMessage":"Counter update statements are not supported","messagePattern":"Counter update statements are not supported","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"tools/stress/src/org/apache/cassandra/io/sstable/StressCQLSSTableWriter.java","lineNumber":702,"sourceCode":"            return TableId.fromUUID(UUID.nameUUIDFromBytes(ArrayUtils.addAll(keyspace.getBytes(), table.getBytes())));\n        }\n\n        /**\n         * Prepares insert statement for writing data to SSTable\n         *\n         * @return prepared Insert statement and it's bound names\n         */\n        private UpdateStatement prepareInsert()\n        {\n            ClientState state = ClientState.forInternalCalls();\n            CQLStatement cqlStatement = insertStatement.prepare(state);\n            UpdateStatement insert = (UpdateStatement) cqlStatement;\n            insert.validate(state);\n\n            if (insert.hasConditions())\n                throw new IllegalArgumentException(\"Conditional statements are not supported\");\n            if (insert.isCounter())\n                throw new IllegalArgumentException(\"Counter update statements are not supported\");\n            if (insert.getBindVariables().isEmpty())\n                throw new IllegalArgumentException(\"Provided insert statement has no bind variables\");\n\n            return insert;\n        }\n    }\n\n    public static <T extends CQLStatement.Raw> T parseStatement(String query, Class<T> klass, String type)\n    {\n        try\n        {\n            CQLStatement.Raw stmt = CQLFragmentParser.parseAnyUnhandled(CqlParser::query, query);\n\n            if (!stmt.getClass().equals(klass))\n                throw new IllegalArgumentException(\"Invalid query, must be a \" + type + \" statement but was: \" + stmt.getClass());\n\n            return klass.cast(stmt);\n        }","sourceCodeStart":684,"sourceCodeEnd":720,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/tools/stress/src/org/apache/cassandra/io/sstable/StressCQLSSTableWriter.java#L684-L720","documentation":"Counter writes cannot be materialized as plain offline SSTables by StressCQLSSTableWriter, since counters require special storage handling in Cassandra. prepareInsert() throws IllegalArgumentException when the parsed UpdateStatement reports isCounter().","triggerScenarios":"Passing an INSERT/UPDATE targeting a counter column (e.g. UPDATE tbl SET c = c + ? or INSERT with counter column) to using(...).","commonSituations":"Bulk-loading counter tables with the stress SSTable writer; schema migrated to counter type after the tooling was built; copy-pasting counter update CQL into the generator.","solutions":["Do not use StressCQLSSTableWriter for counter tables; write via a live cluster connection instead.","Remove counter columns from the SSTable-generation target or use a regular column type.","Load counter increments through normal client writes (e.g. CQL driver) or cassandra-stress.","If exact counter state is needed offline, consult supported import paths for counter tables in your Cassandra version."],"exampleFix":"// before\nbuilder.using(\"UPDATE ks.counters SET c = c + ? WHERE k = ?\");\n// after\nbuilder.using(\"INSERT INTO ks.events (k, v) VALUES (?, ?)\"); // non-counter table","handlingStrategy":"validation","validationCode":"// ensure target table has no counter columns before building the writer\nif (tableHasCounterColumns(schema)) throw new IllegalArgumentException(\"counter tables unsupported by StressCQLSSTableWriter\");","typeGuard":null,"tryCatchPattern":"try { writer = builder.build(); }\ncatch (IllegalArgumentException e) { throw new IllegalStateException(\"use live-cluster writes for counters: \" + e.getMessage(), e); }","preventionTips":["Check schema for counter columns before choosing the SSTable-writer path.","Route counter tables through normal client writes or cassandra-stress.","Avoid schema migrations to counter type on tool-fed tables.","Document counter-table exclusions in load-tooling docs."],"tags":["sstable","cql","counter","unsupported"],"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"}