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

   # Which issue does this PR close?
   
   - Closes #11735
   
   # Rationale for this change
   
   With `ReaderBuilder::with_utf8_view(true)`, the `StringView` arm of 
`Decoder::flush` built a `StringArray` with the correct null buffer, then 
copied it into a `Vec<&str>` that replaced every NULL with `""` before building 
the `StringViewArray`. The resulting array had no null buffer, so every NULL of 
a nullable string field came back as a non-null empty string (`null_count == 
0`), while the same file read with `with_utf8_view(false)` was correct.
   
   # What changes are included in this PR?
   
   - Build the `StringViewArray` with `StringViewArray::from(&StringArray)`, 
which keeps the null buffer and creates views into the existing values buffer 
instead of copying each string through a `Vec<&str>`.
   
   (#11737 proposed the same approach but was closed by its author without 
merging; this picks the fix back up.)
   
   # Are these changes tested?
   
   Yes. Added `test_utf8_view_keeps_nulls_of_nullable_strings`, which writes 
`["a", null, "", null, "b"]` with `AvroWriter` and reads it back with 
`with_utf8_view(true)`. It fails on main (`null_count` 0 instead of 2) and 
passes with the fix. `cargo test -p arrow-avro` and `cargo clippy -p arrow-avro 
--all-targets --all-features -- -D warnings` pass.
   
   # Are there any user-facing changes?
   
   Yes, a bug fix: with `with_utf8_view(true)`, NULL strings are now read as 
nulls instead of empty strings. No API changes.
   
   This PR was prepared with AI assistance and reviewed/tested by the author.
   


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