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

[Parquet] Add BooleanArray based row selection #6624

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

XiangpengHao
Copy link
Contributor

@XiangpengHao XiangpengHao commented Oct 24, 2024

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?

@github-actions github-actions bot added the parquet Changes to the parquet crate label Oct 24, 2024
@XiangpengHao XiangpengHao force-pushed the row-selector3 branch 2 times, most recently from c597e4a to 42938bf Compare October 25, 2024 15:05
@XiangpengHao XiangpengHao marked this pull request as ready for review October 25, 2024 15:06
@XiangpengHao
Copy link
Contributor Author

XiangpengHao commented Oct 25, 2024

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
Copy link
Contributor

tustvold commented Oct 26, 2024

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

Copy link
Contributor

@tustvold tustvold left a comment

Choose a reason for hiding this comment

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

I've not reviewed in fine detail, but the code looks good to me

@alamb
Copy link
Contributor

alamb commented Oct 26, 2024

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

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @XiangpengHao -- I think this is an interesting direction to head (use bitmap for selection). However, I am not sure about this exact implementation)

I left some questions below.

One thing that seems like it might be more useful is to switch RowSelection into an enum so we can dynamically switch between the two representations based on what is actually selected

enum RowSelection {
  Ranges(Vec<Selection>),
  Btitmap(..)
}

I realize one challenge with this is that BooleanArray is part of arrow and not available in Parquet directly.

/// A selection of rows, similar to [`RowSelection`], but based on a boolean array
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BooleanRowSelection {
selector: BooleanBuffer,
Copy link
Contributor

Choose a reason for hiding this comment

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

One question I have while reviewing this PR is "why not just use BooleanArray directly?"

It seems like most of these methods would be generally useful on BooleanArray (or perhaps as kernels) -- and in fact most of them are already (like union is | and intersection is &).

Another thing that might be interesting to do if we really care about performance is to look into implementing in-place updates -- maybe something like https://docs.rs/arrow/latest/arrow/compute/fn.binary_mut.html for BooleanArray)

@XiangpengHao
Copy link
Contributor Author

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
Copy link
Contributor

alamb commented Nov 15, 2024

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

@alamb alamb marked this pull request as draft November 15, 2024 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parquet Changes to the parquet crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants