-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add row_group_is_[max/min]_value_exact to StatisticsConverter
#7574
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3fbf861
feat: add `row_group_is_[max|min]_value_exact` to StatisticsConverter
CookiePieWw 0623f2a
chore: use global const
CookiePieWw 9c5c5c7
test: add null and non-truncated cases in test
CookiePieWw ad433b9
test: add `truncate_stats` to mark [Scenario::TruncatedUTF8]
CookiePieWw b61a495
test: update test cases
CookiePieWw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,9 @@ use chrono::Datelike; | |
| use chrono::{Duration, TimeDelta}; | ||
| use half::f16; | ||
| use parquet::arrow::ArrowWriter; | ||
| use parquet::file::properties::{EnabledStatistics, WriterProperties}; | ||
| use parquet::file::properties::{ | ||
| EnabledStatistics, WriterProperties, DEFAULT_COLUMN_INDEX_TRUNCATE_LENGTH, | ||
| }; | ||
| use std::sync::Arc; | ||
| use tempfile::NamedTempFile; | ||
|
|
||
|
|
@@ -91,10 +93,20 @@ enum Scenario { | |
| PeriodsInColumnNames, | ||
| StructArray, | ||
| UTF8, | ||
| /// UTF8 with max and min values truncated | ||
| TruncatedUTF8, | ||
| UTF8View, | ||
| BinaryView, | ||
| } | ||
|
|
||
| impl Scenario { | ||
| // If the test scenario needs to set `set_statistics_truncate_length` to test | ||
| // statistics truncation. | ||
| fn truncate_stats(&self) -> bool { | ||
| matches!(self, Scenario::TruncatedUTF8) | ||
| } | ||
| } | ||
|
|
||
| fn make_boolean_batch(v: Vec<Option<bool>>) -> RecordBatch { | ||
| let schema = Arc::new(Schema::new(vec![Field::new( | ||
| "bool", | ||
|
|
@@ -631,6 +643,8 @@ fn make_dict_batch() -> RecordBatch { | |
| .unwrap() | ||
| } | ||
|
|
||
| /// Create data batches for the given scenario. | ||
| /// `make_test_file_rg` uses the first batch to inference the schema of the file. | ||
| fn create_data_batch(scenario: Scenario) -> Vec<RecordBatch> { | ||
| match scenario { | ||
| Scenario::Boolean => { | ||
|
|
@@ -987,6 +1001,33 @@ fn create_data_batch(scenario: Scenario) -> Vec<RecordBatch> { | |
| make_utf8_batch(vec![Some("e"), Some("f"), Some("g"), Some("h"), Some("i")]), | ||
| ] | ||
| } | ||
| Scenario::TruncatedUTF8 => { | ||
| // Make utf8 batch with strings longer than 64 bytes | ||
| // to check truncation of row group statistics | ||
| vec![ | ||
| make_utf8_batch(vec![ | ||
| Some(&("a".repeat(64) + "1")), | ||
| Some(&("b".repeat(64) + "2")), | ||
| Some(&("c".repeat(64) + "3")), | ||
| None, | ||
| Some(&("d".repeat(64) + "4")), | ||
| ]), | ||
| make_utf8_batch(vec![ | ||
| Some(&("e".repeat(64) + "5")), | ||
| Some(&("f".repeat(64) + "6")), | ||
| Some(&("g".repeat(64) + "7")), | ||
| Some(&("h".repeat(64) + "8")), | ||
| Some(&("i".repeat(64) + "9")), | ||
| ]), | ||
| make_utf8_batch(vec![ | ||
| Some("j"), | ||
| Some("k"), | ||
| Some(&("l".repeat(64) + "12")), | ||
| Some(&("m".repeat(64) + "13")), | ||
| Some(&("n".repeat(64) + "14")), | ||
| ]), | ||
| ] | ||
| } | ||
| Scenario::UTF8View => { | ||
| // Make utf8_view batch including string length <12 and >12 bytes | ||
| // as the internal representation of StringView is differed for strings | ||
|
|
@@ -1027,11 +1068,15 @@ async fn make_test_file_rg(scenario: Scenario, row_per_group: usize) -> NamedTem | |
| .tempfile() | ||
| .expect("tempfile creation"); | ||
|
|
||
| let props = WriterProperties::builder() | ||
| let mut builder = WriterProperties::builder() | ||
| .set_max_row_group_size(row_per_group) | ||
| .set_bloom_filter_enabled(true) | ||
| .set_statistics_enabled(EnabledStatistics::Page) | ||
| .build(); | ||
| .set_statistics_enabled(EnabledStatistics::Page); | ||
| if scenario.truncate_stats() { | ||
| // The same as default `column_index_truncate_length` to check both stats with one value | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will not be needed after #7578 |
||
| builder = builder.set_statistics_truncate_length(DEFAULT_COLUMN_INDEX_TRUNCATE_LENGTH); | ||
| } | ||
| let props = builder.build(); | ||
|
|
||
| let batches = create_data_batch(scenario); | ||
| let schema = batches[0].schema(); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try throwing a null in the first batch, that seems to clear up the issue with empty string showing up in the stats. It seems like the schema is inferred from the first batch, so all values are not nullable. Putting a null in the first batch fixes that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable for me. But I still wonder if its as expected that a first batch without null values will cause the
Nones in following batches are converted into empty strings.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have to study the API used here in more detail, but I would assume one would usually provide a schema prior to writing batches. The issue here AFAICT is that a null value is written, but the schema says values are not nullable, so the null is converted to an empty string. I think I'd prefer an error be thrown in this instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, with sleep I now see the schema is set in
make_test_file_rg...the first batch is used.arrow-rs/parquet/tests/arrow_reader/mod.rs
Lines 1037 to 1039 in 0ae9f66
Perhaps a note should be added that if nulls are desired, they need to be included in the first batch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah thanks! So it's not a bug then.