Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up filter_run_end_array #6712

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions arrow-select/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,17 +431,17 @@ where
R::Native: AddAssign,
{
let run_ends: &RunEndBuffer<R::Native> = array.run_ends();
let mut values_filter = BooleanBufferBuilder::new(run_ends.len());
let mut new_run_ends = vec![R::default_value(); run_ends.len()];

let mut start = 0u64;
let mut i = 0;
let mut j = 0;
let mut count = R::default_value();
let filter_values = predicate.filter.values();
let run_ends = run_ends.inner();

for mut end in run_ends.inner().into_iter().map(|i| (*i).into() as u64) {
let pred: BooleanArray = BooleanBuffer::collect_bool(run_ends.len(), |i| {
let mut keep = false;

let mut end = run_ends[i].into() as u64;
let difference = end.saturating_sub(filter_values.len() as u64);
end -= difference;

Expand All @@ -450,23 +450,18 @@ where
count += R::Native::from(pred);
keep |= pred
}

// this is to avoid branching
new_run_ends[i] = count;
i += keep as usize;
new_run_ends[j] = count;
j += keep as usize;

values_filter.append(keep);
start = end;
}

new_run_ends.truncate(i);
keep
})
.into();

if values_filter.is_empty() {
new_run_ends.clear();
}
new_run_ends.truncate(j);

let values = array.values();
let pred = BooleanArray::new(values_filter.finish(), None);
let values = filter(&values, &pred)?;

let run_ends = PrimitiveArray::<R>::new(new_run_ends.into(), None);
Expand Down
Loading