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

Set bloom filter on byte array #3284

Merged
merged 4 commits into from Dec 8, 2022

Conversation

viirya
Copy link
Member

@viirya viirya commented Dec 6, 2022

Which issue does this PR close?

Closes #3275.

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added the parquet Changes to the parquet crate label Dec 6, 2022
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.

Thank you for this, that was fast 🎉

I think this has an issue with its handling of nulls, but otherwise just some minor nits 👍

// encode the values into bloom filter if enabled
if let Some(bloom_filter) = &mut encoder.bloom_filter {
for idx in 0..values.len() {
bloom_filter.insert(&values.value(idx));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs to take into account nulls? Otherwise it will add whatever happens to be in the null slot, most likely an empty string, into the bloom filter?

Copy link
Member Author

Choose a reason for hiding this comment

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

Skipped null slots now.

if let Some(sbbf) =
row_group_reader.get_column_bloom_filter(column_index)
{
if row_group.num_rows() >= positive_values.len() as i64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this if statement for?

Copy link
Member Author

Choose a reason for hiding this comment

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

The function creating the parquet file is configured with various row group size. If the row group is smaller than positive values, not all these values will be in the bloom filter. Then we may not be able to find all values from it (the following assert! will fail).

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we could test all the row groups in aggregate?

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed it to collect all bloom filters and test against values together.

}

#[test]
fn binary_column_bloom_filter() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we could get a test of nulls and empty strings?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added one test for that.

@@ -448,6 +448,12 @@ impl AsBytes for [u8] {
}
}

impl AsBytes for &[u8] {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is redundant given the implementation above? Just add &

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed it.

@@ -543,7 +549,7 @@ impl ColumnValueEncoder for ByteArrayEncoder {
fn encode<T>(values: T, indices: &[usize], encoder: &mut ByteArrayEncoder)
where
T: ArrayAccessor + Copy,
T::Item: Copy + Ord + AsRef<[u8]>,
T::Item: Copy + Ord + AsRef<[u8]> + AsBytes,
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if just adding .as_ref() to the call site would be sufficient instead of adding an additional trait bound? Not sure though. It isn't a major thing, just a very minor nit

Copy link
Member Author

@viirya viirya Dec 8, 2022

Choose a reason for hiding this comment

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

.as_ref() is okay, just requires one trait bound (?Sized) to insert.

@tustvold
Copy link
Contributor

tustvold commented Dec 8, 2022

I took the liberty of fixing clippy for this

@tustvold tustvold merged commit fa1f611 into apache:master Dec 8, 2022
@viirya
Copy link
Member Author

viirya commented Dec 8, 2022

Thank you @tustvold

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.

Support writing BloomFilter in arrow_writer
2 participants