oscerd opened a new pull request, #29061:
URL: https://github.com/apache/camel/pull/29061

   Fixes [CAMEL-26214](https://issues.apache.org/jira/browse/CAMEL-26214), 
found while adding the catalog body types (CAMEL-24961).
   
   ## 1. A List of Double vector fails with ArrayStoreException
   
   **Was:** CREATE, UPDATE_BY_ID and QUERY copied the body List into a 
`Float[]` with `toArray(new Float[0])`. A List of Double (what a JSON array 
unmarshals to), or a List of any other number type, therefore failed with a raw 
`ArrayStoreException`. A `double[]` or `Double[]` body failed the same way, 
because Camel converts it to a List of Double. The optional 
`CamelWeaviateQueryVector` header of HYBRID_QUERY was copied the same way and 
had the same failure.
   
   **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()`. The `CamelWeaviateQueryVector` 
header takes the same values. 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
   
   `WeaviateVectorBodyTest` is new. It runs against a fake Weaviate: the REST 
API on a JDK `HttpServer`, and the gRPC search service on a gRPC server on a 
random port. The fake records the requests the client sends, so the test needs 
no Weaviate.
   
   - CREATE, UPDATE_BY_ID and QUERY each take a List of Float, a List of 
Double, a List of BigDecimal, a `float[]`, a `double[]` and a `Double[]` (18 
cases). The test checks the vector in the JSON of the stored object, or in the 
gRPC search request.
   - HYBRID_QUERY takes a List of Double in the `CamelWeaviateQueryVector` 
header.
   - A String body, a List of String and a List with a null element fail with 
the expected exception and message, and nothing is sent.
   
   Without the fix, 14 of the 20 tests fail:
   - the List of Double, List of BigDecimal, `double[]` and `Double[]` cases of 
the three actions, and the HYBRID_QUERY header, fail with the old 
`ArrayStoreException`;
   - the failure test fails because the old message does not name the expected 
types.
   
   The 6 that pass are the List of Float and `float[]` cases of the three 
actions, which already worked.
   
   Module: 26 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 `weaviate.json` and its catalog copy. `weaviate-component.adoc`, 
and its catalog copy, has a new paragraph on the vector of CREATE, 
UPDATE_BY_ID, QUERY and the HYBRID_QUERY header.
   
   ## 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 Weaviate as it is.
   - A `CamelWeaviateQueryVector` header that Camel cannot convert to a List, 
such as a String, is still ignored, as before.
   - No option or header changed. The `List<Float>` javaType of the 
`CamelWeaviateQueryVector` header is kept.
   - 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 an `ArrayStoreException`.
   
   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]

Reply via email to