alamb commented on code in PR #9653:
URL: https://github.com/apache/arrow-rs/pull/9653#discussion_r3133835026
##########
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:
> Yes, I considered the mem::take approach, but it feels brittle if the
control flow changes in the future or if there is a panic. Cloning the Arc is a
bit sad because of the atomic, but it is foolproof 🤷
You could also use an RAAI type thing perhaps 🤔
--
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]