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

Fix page size on dictionary fallback #2854

Merged
merged 3 commits into from Oct 10, 2022
Merged

Fix page size on dictionary fallback #2854

merged 3 commits into from Oct 10, 2022

Conversation

thinkharderdev
Copy link
Contributor

Which issue does this PR close?

Closes #2853

Rationale for this change

On fallback ByteArrayEncoder wasn't tracking the number of values written so when the dictionary page hits the limit and we fallback, all remaining data was written in a single data page.

What changes are included in this PR?

Make sure ByteArrayEncoder tracks the number of encoded values after it falls back to the fallback encoder

Are there any user-facing changes?

This will change the way data pages are laid out in some cases.

No

No

@github-actions github-actions bot added the parquet Changes to the parquet crate label Oct 9, 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 👍

@@ -1108,6 +1110,55 @@ mod tests {
roundtrip(batch, Some(SMALL_SIZE / 2));
}

#[test]
fn arrow_writer_page_size() {
let mut rng = thread_rng();
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 we should either seed this, or loosen the assert below. Otherwise I worry that depending on what values are generated, we may end up with more or less pages (as the dictionary page will only spill once it has seen sufficient different values, which technically could occur at any point)


let props = WriterProperties::builder()
.set_max_row_group_size(usize::MAX)
.set_data_pagesize_limit(256)
Copy link
Contributor

Choose a reason for hiding this comment

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

You could potentially set the dictionary page size smaller to verify that as well, but up to you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I think there are still some issues here. It is still ignoring the size limit. It is at least respecting the write_batch_size though.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is expected and I believe consistent with other parquet writers. The limit is best effort

@@ -551,7 +551,10 @@ where

match &mut encoder.dict_encoder {
Some(dict_encoder) => dict_encoder.encode(values, indices),
None => encoder.fallback.encode(values, indices),
None => {
encoder.num_values += indices.len();
Copy link
Contributor

@tustvold tustvold Oct 9, 2022

Choose a reason for hiding this comment

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

I'm guessing the problem was that whilst the estimated_data_page_size would increase, the lack of any values would cause it to erroneously not try to flush the page?

In particular https://github.com/apache/arrow-rs/blob/master/parquet/src/column/writer/mod.rs#L567

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, exactly

@@ -551,7 +551,10 @@ where

match &mut encoder.dict_encoder {
Some(dict_encoder) => dict_encoder.encode(values, indices),
None => encoder.fallback.encode(values, indices),
None => {
encoder.num_values += indices.len();
Copy link
Contributor

@tustvold tustvold Oct 9, 2022

Choose a reason for hiding this comment

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

Should we be doing this regardless of if we've fallen back? I think currently this will fail to flush a dictionary encoded data page even if it has reached sufficient size?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe, when we do it that way it causes a panic which may also be a bug.

General("Must flush data pages before flushing dictionary")'

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 we need to reset num_values to 0 when we flush a data page

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it already does that right?

num_values: std::mem::take(&mut self.num_values),

Copy link
Member

@Ted-Jiang Ted-Jiang left a comment

Choose a reason for hiding this comment

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

👍

@tustvold tustvold merged commit 0268bba into master Oct 10, 2022
@ursabot
Copy link

ursabot commented Oct 10, 2022

Benchmark runs are scheduled for baseline = c3aac93 and contender = 0268bba. 0268bba is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

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.

parquet::arrow::arrow_writer::ArrowWriter ignores page size properties
4 participants