apache / arrow-rs

Official Rust implementation of Apache Arrow
https://arrow.apache.org/
Apache License 2.0
2.63k stars 803 forks source link

[Parquet] Add BooleanArray based row selection #6624

Open XiangpengHao opened 1 month ago

XiangpengHao commented 1 month ago

Which issue does this PR close?

Part of #5523

Rationale for this change

Implement the row selection based on BooleanArray.

The implementation only covers the core operations like union, intersection, and_then, and is already quite large. Once we agree with the generally direction, I'll add remaining implementaions in follow up PRs.

What changes are included in this PR?

I added more benchmark to cover different selection ratios, as suggested by @tustvold and @alamb

Are there any user-facing changes?

XiangpengHao commented 1 month ago

The benchmark can take a while to run, here're some of my results visualized by ChatGPT. Note that both x and y axies are in log scale. slice is the current slice-based row selection, boolean is the boolean mask based selection.

Selection ratio 1e-5 means 0.0001% of the rows are selected, 0.3 means 30% are selected, and so on.

image

image

image

image

tustvold commented 1 month ago

Perhaps we could model the number of disjoint selections as opposed to raw selectivity, this more accurately models the sorts of selection one gets from evaluation against the page index (which necessarily has page level granularity)

Edit: although the methods benchmarked are those used for late materialization, so perhaps it doesn't matter

alamb commented 1 month ago

I will try and find time to review this today or tomorrow as well -- thank you @XiangpengHao and @tustvold

XiangpengHao commented 2 weeks ago

switch RowSelection into an enum so we can dynamically switch

That should work, my initial thoughts was to only use bitmap-based selectors when evaluating predicates (i.e., when filter pushdown is enabled); and always do range-based selectors otherwise.

"why not just use BooleanArray directly?"

I agree that most of the functionality overlaps with BooleanBuffer and can be implemented there. Will try to file a separate pr to extract the most common ones to BooleanBuffer in the next few days.

alamb commented 1 week ago

Marking as draft as I believe we plan additonal work for this PR