davsclaus opened a new pull request, #28922: URL: https://github.com/apache/camel/pull/28922
Fixes [CAMEL-26150](https://issues.apache.org/jira/browse/CAMEL-26150). ### 1. Query results in binary formats were corrupted **What was wrong:** `ClickHouseProducer.doQuery` read the response into `new String(bytes, UTF_8)` for every `format`. With a binary format such as `RowBinary`, `Native` or `Parquet`, the bytes that are not valid UTF-8 were replaced, so the result could not be decoded and no error was raised. **What changed:** a query with a binary format now sets the body as `byte[]`. Text formats (`JSONEachRow`, `CSV`, `TSV`, ...) still give a `String`. The check uses `ClickHouseFormat.isBinary()` from clickhouse-data, except for `NDJSON`: clickhouse-data flags it as binary, but it is JSON text (one object per line), so it stays a `String`. The `@BodyTypes` of the endpoint now say a query gives text or bytes (and no longer a fixed `java.lang.String`). ### 2. Inserting a List of Maps, or of objects whose class is not registered, failed with an NPE **What was wrong:** `insertList` passed the List to `client.insert(table, list, settings)`. client-v2 only inserts a List of objects whose class was registered on the Client with `Client.register(Class, TableSchema)`. When nothing is registered for the table, client-v2 fails with `NullPointerException: Cannot invoke "java.lang.Boolean.booleanValue()"`, which does not say why. **What changed:** - A List whose first element is a `Map` fails before the call with a `ClickHouseException` saying a List of Maps is not supported and to marshal the rows to the `format` (such as `JSONEachRow`). - A `NullPointerException` thrown by `client.insert` for a List is rethrown as a `ClickHouseException` that names the element class and the table and says to register the class (the NPE is kept as the cause). client-v2 has no public method to check whether a class is registered, so this is the only place to catch it. When the table is registered but for another class, client-v2 already throws a clear `IllegalArgumentException` ("No serializer found for column ..."), which is left as is. ### 3. Doc: CamelClickHouseReadRows The header is set from `QueryResponse.getReadRows()`, the number of rows the server read (scanned). Its description now says so, and that it is not the number of rows in the result (with a WHERE or a LIMIT it is usually more). The header value is unchanged. ### Tests - `ClickHouseProducerTest` (mocked Client): `queryWithBinaryFormatReturnsBytes`, `queryWithNdjsonFormatReturnsString`, `insertListOfMapsFailsWithClearMessage`, `insertListWithoutRegisteredClassFailsWithClearMessage`. The two existing List tests now use a POJO instead of Maps. - `ClickHouseProducerIT` (ClickHouse in Docker via test-infra): `queryWithBinaryFormatReturnsBytes` (checks the exact RowBinary bytes of a row with `id=200` and `name='é'`), `insertListOfMapsFailsWithClearMessage`, `insertListWithoutRegisteredClassFailsWithClearMessage`. - Without the fix, 3 of the new unit tests and 3 of the new ITs fail (String instead of byte[], NPE instead of ClickHouseException, no exception for a List of Maps with the mock). With the fix: unit tests 23/23, ITs 5/5. ### Docs and generated files - `clickhouse-component.adoc`: query body type per format, List of Map not supported, the meaning of `CamelClickHouseReadRows`. - Upgrade guide 4.24: new `camel-clickhouse` section (a query in a binary format now returns `byte[]`; the List insert failures are now a `ClickHouseException`). - Regenerated `clickhouse.json` (component and catalog), the catalog doc copy and `ClickHouseEndpointBuilderFactory`. ### Not changed - An empty List body still fails with client-v2's `IllegalArgumentException: Data cannot be empty`; not part of this issue. - No conversion of a List of Maps into rows: the issue asks for a clear failure, and the body type docs already say to marshal first. _Claude Code on behalf of Claus Ibsen (davsclaus)_ 🤖 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]
