davsclaus opened a new pull request, #30319: URL: https://github.com/apache/camel/pull/30319
[CAMEL-27147](https://issues.apache.org/jira/browse/CAMEL-27147): the `cql` producer binds a `Map` body by name. Each named marker of the statement, such as `:login`, takes the value of the `Map` entry of that name. Until now the producer bound values only by position (`Object[]`, `Collection`, or a single value), so a statement had to use `?` markers with the body listing the values in that order. A `Map` body was bound as one single value. ```yaml - unmarshal: json: {} # {"login": "davsclaus", "firstName": "Claus", "lastName": "Ibsen"} - to: uri: cql://localhost/camel_ks parameters: cql: "insert into camel_user(login, first_name, last_name) values (:login, :firstName, :lastName)" ``` This is what camel-sql does with `:#name` and a `Map` body. It is needed for the Kamelet `cassandra-sink`, which takes a JSON array today and should take a JSON object, like the SQL Kamelets do. ### How - **`prepareStatements=true` (default):** the values are taken from the `Map` in the order of `PreparedStatement.getVariableDefinitions()`, and bound with the same `bind(Object...)` as before. - **`prepareStatements=false`:** `SimpleStatement.newInstance(cql, Map)`. - **Keys:** matched ignoring case, as CQL does for an unquoted name (`:firstName` is `firstname` in CQL). Keys the statement does not use are ignored. - **A marker with no entry** fails the message with an `IllegalArgumentException` that names the marker. - **An `Object[]`, a `Collection` or a single value** binds by position, as before. ### Upgrade note A `Map` body was bound as the value of a single marker before. To keep that, such as for a column of type `map`, wrap the `Map` in a `List`. This is in the 4.24 upgrade guide, and the component docs describe both ways of binding. ### Tests `CassandraComponentProducerNamedIT`, against Cassandra in a test container: - prepared and unprepared inserts from a `Map` that has its keys in another order, camelCase keys and an extra key; - a prepared update whose CQL is in the `CamelCqlQuery` header; - a missing value, which fails and names the marker. All 4 fail on the old producer. The existing producer ITs (13 tests) still pass. _Claude Code on behalf of Claus Ibsen_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
