{"record":{"id":"50562334fa537116","repo":"apache/cassandra","slug":"conditional-statements-are-not-supported-505623","errorCode":null,"errorMessage":"Conditional statements are not supported","messagePattern":"Conditional statements are not supported","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"tools/stress/src/org/apache/cassandra/io/sstable/StressCQLSSTableWriter.java","lineNumber":700,"sourceCode":"        private static TableId deterministicId(String keyspace, String table)\n        {\n            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","sourceCodeStart":682,"sourceCodeEnd":718,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/tools/stress/src/org/apache/cassandra/io/sstable/StressCQLSSTableWriter.java#L682-L718","documentation":"StressCQLSSTableWriter prepares the user-provided INSERT for offline SSTable generation, which cannot honor lightweight transactions. prepareInsert() inspects the parsed UpdateStatement and throws IllegalArgumentException if hasConditions() is true (e.g. IF NOT EXISTS or IF col = x).","triggerScenarios":"Passing an INSERT with IF NOT EXISTS or an UPDATE with IF <condition> to builder.using(...) (via preparedInsert).","commonSituations":"Reusing an application LWT insert statement directly for bulk loading; copying production CQL that uses conditional writes for idempotency; ORM-generated inserts with IF NOT EXISTS defaults.","solutions":["Remove IF NOT EXISTS / IF conditions from the insert statement.","Ensure row uniqueness in your data instead of relying on LWT semantics.","Use a plain INSERT with the full primary key and all columns.","Pre-deduplicate input rows before writing if overwrites are a concern."],"exampleFix":"// before\nbuilder.using(\"INSERT INTO ks.tbl (k, v) VALUES (?, ?) IF NOT EXISTS\");\n// after\nbuilder.using(\"INSERT INTO ks.tbl (k, v) VALUES (?, ?)\");","handlingStrategy":"validation","validationCode":"String cql = insertStmt.trim().toLowerCase();\nif (cql.contains(\" if \") || cql.contains(\"if not exists\")) throw new IllegalArgumentException(\"conditions not allowed in SSTable writer\");\nbuilder.using(insertStmt);","typeGuard":null,"tryCatchPattern":"try { writer = builder.build(); }\ncatch (IllegalArgumentException e) { throw new IllegalStateException(\"strip IF conditions from insert: \" + e.getMessage(), e); }","preventionTips":["Never reuse application LWT statements for bulk SSTable generation.","Enforce uniqueness in source data instead of IF NOT EXISTS.","Review generated CQL for condition keywords before use.","Document that the writer accepts plain writes only."],"tags":["sstable","cql","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"}