xgbtxy opened a new pull request, #12445:
URL: https://github.com/apache/arrow-rs/pull/12445

   # Which issue does this PR close?
   
   - None (discovered via differential consistency testing between 
`VariantToJson::to_json_value` and `VariantToJson::to_json_string`).
   
   # Rationale for this change
   
   Standard JSON (RFC 8259) does not support non-finite floating-point numbers 
(`NaN`, `Infinity`, `-Infinity`). `VariantToJson::to_json_value` already 
rejects non-finite `Variant::Float` and `Variant::Double` values with 
`ArrowError::InvalidArgumentError("Invalid float value")` / `"Invalid double 
value"`.
   
   However, `VariantToJson::to_json` (and therefore `to_json_string` and 
`parquet_variant_compute::variant_to_json`) passed non-finite values directly 
to `ryu::Buffer::format`, silently emitting invalid unquoted JSON such as 
`NaN`, `inf`, `-inf`, or `{"score":NaN}`.
   
   # What changes are included in this PR?
   
   - Guard `!f.is_finite()` for `Variant::Float` and `Variant::Double` in 
`VariantToJson::to_json` in `parquet-variant-json/src/to_json.rs` to return 
`ArrowError::InvalidArgumentError("Invalid float value")` / `"Invalid double 
value"`, matching `to_json_value`.
   - Use `ryu::Buffer::new().format_finite(*f)` after confirming finiteness.
   
   # Are these changes tested?
   
   Yes. Extended `to_json::tests::test_float_nan_inf_handling` in 
`parquet-variant-json/src/to_json.rs` to assert that `to_json_string` and 
`to_json` return the expected errors for `Variant::Float` / `Variant::Double` 
`NAN`, `INFINITY`, and `NEG_INFINITY` as well as nested `Variant::Object` and 
`Variant::List` values containing non-finite floats. Verified against 
`parquet-variant-json` (unit and doc tests) and `parquet-variant-compute`.
   
   # Are there any significant user-facing changes?
   
   `VariantToJson::to_json`, `VariantToJson::to_json_string`, and 
`parquet_variant_compute::variant_to_json` now return 
`Err(ArrowError::InvalidArgumentError(...))` for non-finite `Float`/`Double` 
values instead of writing invalid JSON tokens (`NaN`, `inf`, `-inf`), making 
them consistent with `VariantToJson::to_json_value`.
   
   # AI usage disclosure
   
   This PR was prepared with AI coding assistant support for locating the 
inconsistency, drafting the fix and unit test extensions, and verifying 
compilation and tests; all changes and test results were reviewed directly.


-- 
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