oscerd opened a new pull request, #29062: URL: https://github.com/apache/camel/pull/29062
Fixes [CAMEL-26215](https://issues.apache.org/jira/browse/CAMEL-26215), found while adding the catalog body types (CAMEL-24961). ## 1. A List of Double vector fails with ClassCastException **Was:** UPSERT and SIMILARITY_SEARCH read the body as a `List<Float>` and assigned each element to a `Float`, so a List of Double (what a JSON array unmarshals to), or a List of any other number type, failed with a raw `ClassCastException`. A `double[]` or `Double[]` body failed the same way, because Camel converts it to a List of Double. **Now:** The vector is a `float[]`, a List of numbers, or another body Camel converts to a List (such as a `double[]`, a `Float[]` or a `Double[]`). Each element is converted with `Number.floatValue()`. A List with an element that is null or not a number fails with an `IllegalArgumentException` that gives the index and the type of the element, but not its value. Any other body fails with an `InvalidPayloadException` whose message names the expected types. ## Tests `PgVectorVectorBodyTest` is new. A stub DataSource records the `PGvector` that each statement receives, so the test needs no database. UPSERT and SIMILARITY_SEARCH each take a List of Float, a List of Double, a List of BigDecimal, a `float[]`, a `double[]` and a `Double[]` (12 cases). One more test checks that a String body, a List of String and a List with a null element fail with the expected exception and message. Without the fix, 9 of the 13 tests fail: - the List of Double, List of BigDecimal, `double[]` and `Double[]` cases fail with the old `ClassCastException`; - the failure test fails because the old message does not name the expected types. The 4 that pass are the List of Float and `float[]` cases of both actions, which already worked. Module: 18 tests, 0 failures. ## Docs and generated files The producerIn body types description of the endpoint now says the vector is a List of numbers, such as the List of Double a JSON array unmarshals to, or a float or double array. It no longer says a List of Double fails. This regenerates `pgvector.json` and its catalog copy. The UPSERT and SIMILARITY_SEARCH entries in `pgvector-component.adoc`, and its catalog copy, say the same. ## Not changed - A `float[]` body already worked through Camel's array-to-List conversion. It is now used as is. - An empty List is still passed to the database as it is. - No option or header changed. The two `@SuppressWarnings("unchecked")` that the old casts needed are removed. - There is no upgrade guide entry, because every body that worked before still works the same way. A List with an element that is not a number now fails with an `IllegalArgumentException` instead of a `ClassCastException`. Main only, as the other fixes of the CAMEL-24961 follow-ups. _Claude Code on behalf of Andrea Cosentino (oscerd)_ 🤖 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]
