mbutrovich opened a new issue, #12238:
URL: https://github.com/apache/arrow-rs/issues/12238

   #### Describe the bug
   
   
[`NullBufferBuilder::finish`](https://github.com/apache/arrow-rs/blob/9c9486188744e80ec86c3b2bcdd649b89945ffe5/arrow-buffer/src/builder/null.rs#L224-L231)
 documents "Returns `None` if the builder only contains `true`s". Once the 
bitmap is materialized, it returns `Some` even when no null was appended or 
every null was cleared. `finish_cloned` and `build` behave the same way. 
`append_n_nulls(0)` materializes the bitmap without appending a null, and 
`set_bit(i, true)` can clear the only null.
   
   #### To Reproduce
   
   ```rust
   use arrow_buffer::NullBufferBuilder;
   
   fn main() {
       let mut b = NullBufferBuilder::new(0);
       b.append_n_nulls(0);
       b.append_non_null();
       println!("{:?}", b.finish_cloned().map(|n| n.null_count())); // Some(0)
       println!("{:?}", b.finish().map(|n| n.null_count()));        // Some(0)
   
       let mut b = NullBufferBuilder::new(0);
       b.append_null();
       b.set_bit(0, true);
       println!("{:?}", b.build().map(|n| n.null_count()));         // Some(0)
   }
   ```
   
   #### Expected behavior
   
   `finish`, `finish_cloned`, and `build` return `None` when the builder 
contains no nulls, as the `finish` docs say. If returning `Some` is intended, 
the docs should say that `None` means the bitmap was never materialized, so 
callers know to filter on `null_count()`.
   
   #### Additional context
   
   Builders that construct their arrays through `ArrayData` hide this, because 
`ArrayDataBuilder::build` drops a null buffer with no nulls 
([data.rs](https://github.com/apache/arrow-rs/blob/9c9486188744e80ec86c3b2bcdd649b89945ffe5/arrow-data/src/data.rs#L2465)).
 #12228 builds arrays directly in the builders' `finish`, so they would return 
a `NullBuffer` with no nulls unless they filter it.
   
   #### Willingness to contribute
   
   I cannot contribute a fix at this time.


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