HippoBaro commented on code in PR #9653:
URL: https://github.com/apache/arrow-rs/pull/9653#discussion_r3089965804
##########
parquet/src/arrow/arrow_writer/levels.rs:
##########
@@ -625,37 +666,54 @@ impl LevelInfoBuilder {
fn write_leaf(info: &mut ArrayLevels, range: Range<usize>) {
let len = range.end - range.start;
- match &mut info.def_levels {
- Some(def_levels) => {
- def_levels.reserve(len);
- info.non_null_indices.reserve(len);
-
- match &info.logical_nulls {
- Some(nulls) => {
- assert!(range.end <= nulls.len());
- let nulls = nulls.inner();
- def_levels.extend(range.clone().map(|i| {
- // Safety: range.end was asserted to be in bounds
earlier
- let valid = unsafe { nulls.value_unchecked(i) };
- info.max_def_level - (!valid as i16)
- }));
- info.non_null_indices.extend(
- BitIndexIterator::new(nulls.inner(),
nulls.offset() + range.start, len)
- .map(|i| i + range.start),
- );
- }
- None => {
- let iter = std::iter::repeat_n(info.max_def_level,
len);
- def_levels.extend(iter);
- info.non_null_indices.extend(range);
- }
- }
+ // Fast path: entire leaf array is null
+ if let Some(nulls) = &info.logical_nulls {
+ if !matches!(info.def_levels, LevelData::Absent) &&
nulls.null_count() == nulls.len() {
+ info.extend_uniform_levels(info.max_def_level - 1,
info.max_rep_level, len);
+ return;
+ }
+ }
+
+ match info.logical_nulls.clone() {
Review Comment:
To appease the borrow-checker gods. The match arms need `&mut info` (for
`extend_def_levels` etc.) Matching on `&info.logical_nulls` would hold a shared
borrow on info for the entire arm, blocking the `&mut self` calls.
No clean way around it AFAICT.
--
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]