{"record":{"id":"61eb606a2ea26875","repo":"apache/cassandra","slug":"provided-insert-statement-has-no-bind-variables","errorCode":null,"errorMessage":"Provided insert statement has no bind variables","messagePattern":"Provided insert statement has no bind variables","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"tools/stress/src/org/apache/cassandra/io/sstable/StressCQLSSTableWriter.java","lineNumber":704,"sourceCode":"\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        }\n        catch (RecognitionException | RequestValidationException e)\n        {","sourceCodeStart":686,"sourceCodeEnd":722,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/tools/stress/src/org/apache/cassandra/io/sstable/StressCQLSSTableWriter.java#L686-L722","documentation":"For offline SSTable writing, every value must be bound at runtime via rawAddRow. prepareInsert() throws IllegalArgumentException when the parsed statement has no bind variables at all, because there would be nothing to bind per row and the writer cannot compute partition keys or clustings.","triggerScenarios":"Passing a fully literal INSERT (no '?' placeholders) such as INSERT INTO ks.tbl (k, v) VALUES ('a', 1) to using(...).","commonSituations":"Hard-coded sample data inserted as a literal string; template generation code that inlined values instead of parameters; misunderstanding that rawAddRow values map to bound variables.","solutions":["Replace literal values in the INSERT with '?' bind variables.","Pass actual row values per record via rawAddRow(Object[]/List/Map) instead of baking them into the CQL string.","Verify getBindVariables() is non-empty conceptually: one '?' per column in the INSERT.","For one-off static rows, still parameterize and bind once."],"exampleFix":"// before\nbuilder.using(\"INSERT INTO ks.tbl (k, v) VALUES ('a', 1)\");\n// after\nbuilder.using(\"INSERT INTO ks.tbl (k, v) VALUES (?, ?)\");\nwriter.rawAddRow(\"a\", 1);","handlingStrategy":"validation","validationCode":"String cql = insertStmt;\nint placeholders = cql.length() - cql.replace(\"?\", \"\").length();\nif (placeholders == 0) throw new IllegalArgumentException(\"INSERT must contain ? bind variables\");","typeGuard":null,"tryCatchPattern":"try { writer = builder.build(); }\ncatch (IllegalArgumentException e) { throw new IllegalStateException(\"parameterize the insert statement: \" + e.getMessage(), e); }","preventionTips":["Always write INSERTs with '?' placeholders and bind values via rawAddRow.","Never inline literal values into the CQL string.","Lint generated statements for '?' presence.","Keep row data in code/data files, not in the statement."],"tags":["sstable","cql","bind-variables"],"backgroundTag":"missing-required-argument","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"}