{"record":{"id":"4b9aaf7413a9214a","repo":"apache/cassandra","slug":"conditional-statements-are-not-supported","errorCode":null,"errorMessage":"Conditional statements are not supported","messagePattern":"Conditional 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":917,"sourceCode":"            if (partitioner != null)\n                builder.partitioner(partitioner);\n\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":899,"sourceCodeEnd":927,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java#L899-L927","documentation":"CQLSSTableWriter is a bulk-loading API that translates an INSERT/UPDATE bind into direct SSTable writes; it bypasses the normal write path, so Lightweight Transaction (LWT) conditions (IF ... EXISTS etc.) cannot be honored. When preparing the user-supplied modification statement, if preparedModificationStatement.hasConditions() the Builder throws IllegalArgumentException to reject conditional statements up front.","triggerScenarios":"Passing a statement containing conditions to CQLSSTableWriter.builder().withPreparedStatement / RawStatement-based builders — e.g. 'INSERT INTO t ... IF NOT EXISTS' or 'UPDATE t ... IF col = x' — then calling build().","commonSituations":"Reusing application CQL strings that use LWT for idempotency inside a bulk-load script; copying statements from a coordinator path into an offline SSTable writer.","solutions":["Remove the conditional clause (IF NOT EXISTS / IF <condition>) from the statement used with CQLSSTableWriter","Ensure uniqueness out-of-band: check for existing keys beforehand or deduplicate the input data before loading","Use the regular driver/LWT path instead of CQLSSTableWriter if conditional semantics are required"],"exampleFix":"// before\nString cql = \"INSERT INTO ks.t (k, v) VALUES (?, ?) IF NOT EXISTS\";\n// after\nString cql = \"INSERT INTO ks.t (k, v) VALUES (?, ?)\";","handlingStrategy":"validation","validationCode":"if (cql.toUpperCase().matches(\".*\\\\bIF\\\\s+(NOT\\\\s+EXISTS|.*=).*\"))\n    throw new IllegalArgumentException(\"CQLSSTableWriter does not support conditional statements\");","typeGuard":null,"tryCatchPattern":"try { builder.build(); }\ncatch (IllegalArgumentException e) {\n    if (e.getMessage().equals(\"Conditional statements are not supported\"))\n        // strip IF clause and rebuild\n}","preventionTips":["Keep bulk-load CQL in separate templates without LWT clauses","Validate statements for IF conditions before handing them to the builder","Use regular driver sessions when conditional writes are required"],"tags":["sstable","bulk-loading","lwt","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"}