Skip to content

chore: deduplicate filter nulls code in coalesce/filter kernel#10348

Open
Jefffrey wants to merge 1 commit into
apache:mainfrom
Jefffrey:dedup-filter-null-fn
Open

chore: deduplicate filter nulls code in coalesce/filter kernel#10348
Jefffrey wants to merge 1 commit into
apache:mainfrom
Jefffrey:dedup-filter-null-fn

Conversation

@Jefffrey

Copy link
Copy Markdown
Contributor

whilst reviewing #10236 i noticed we have a little code duplication, so remedying that

@github-actions github-actions Bot added the arrow Changes to the arrow crate label Jul 15, 2026
let nulls = unsafe {
NullBuffer::new_unchecked(BooleanBuffer::new(nulls, 0, filter.count()), null_count)
};
self.nulls.append_buffer(&nulls);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since filter_nulls() already creates the nullbuffer for us, just use that

/// Filters the given `nulls` buffer using this predicate.
///
/// Returns `None` when there is nothing to track in the output, either
/// because the input `nulls` was `None`, the input had no nulls, or the
/// filtered result has no nulls. Otherwise returns the filtered
/// [`NullBuffer`] with its precomputed null count.
pub fn filter_nulls(&self, nulls: Option<&NullBuffer>) -> Option<NullBuffer> {
let nulls = nulls?;
if nulls.null_count() == 0 {
return None;
}
let nulls = filter_bits(nulls.inner(), self);
// The filtered `nulls` has a length of `self.count` bits and therefore
// the null count is this minus the number of valid bits
let null_count = self.count - nulls.count_set_bits_offset(0, self.count);
if null_count == 0 {
return None;
}
let buffer = BooleanBuffer::new(nulls, 0, self.count);
debug_assert_eq!(null_count, buffer.len() - buffer.count_set_bits());
// SAFETY: `null_count` was derived from `buffer` above, so it matches
// the number of unset bits as required by `new_unchecked`.
Some(unsafe { NullBuffer::new_unchecked(buffer, null_count) })
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant