mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-20 00:20:47 +00:00
alternator, vector: add validation of non-finite numbers in Query
Non-finite numbers (Inf, NaN) don't make sense in vector search, and also not allowed in the DynamoDB API as numbers. But the parsing code in Query's QueryVector accepted "Inf" and "NaN" and then failed to send the request to the vector store, resulting in a strange error message. Let's fix it in the parsing code. We have a test (test_query_vectorsearch_queryvector_bad_number_string) that verifies this fix. Signed-off-by: Nadav Har'El <nyh@scylladb.com>
This commit is contained in:
@@ -1313,7 +1313,7 @@ static future<executor::request_return_type> query_vector(
|
||||
std::string_view num_str = rjson::to_string_view(*n_val);
|
||||
float f;
|
||||
auto [ptr, ec] = std::from_chars(num_str.data(), num_str.data() + num_str.size(), f);
|
||||
if (ec != std::errc{} || ptr != num_str.data() + num_str.size()) {
|
||||
if (ec != std::errc{} || ptr != num_str.data() + num_str.size() || !std::isfinite(f)) {
|
||||
co_return api_error::validation(
|
||||
format("VectorSearch QueryVector element '{}' is not a valid number", num_str));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user