-
Notifications
You must be signed in to change notification settings - Fork 2k
Support parquet page filtering on min_max for decimal128 and string columns
#4255
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 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8a79f47
Support parquet page filtering for string columns
alamb fc84754
Support parquet page filtering on min_max for decimal128 columns
Ted-Jiang a719dff
Update datafusion/core/src/physical_plan/file_format/parquet/page_fil…
Ted-Jiang 4e29644
Avoid unwarp
Ted-Jiang 5b6c478
reorg test code
Ted-Jiang 4c81dca
add test for page index
Ted-Jiang d0bea7b
fix commet
Ted-Jiang 9ebe563
remove code
Ted-Jiang 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
Support parquet page filtering on min_max for decimal128 columns
Signed-off-by: yangjiang <yangjiang@ebay.com>
- Loading branch information
commit fc8475439bbb5613dc09648e491e0d7ec7d09283
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 |
|---|---|---|
|
|
@@ -18,12 +18,15 @@ | |
| //! Contains code to filter entire pages | ||
|
|
||
| use arrow::array::{ | ||
| BooleanArray, Float32Array, Float64Array, Int32Array, Int64Array, StringArray, | ||
| BooleanArray, Decimal128Array, Float32Array, Float64Array, Int32Array, Int64Array, | ||
| StringArray, | ||
| }; | ||
| use arrow::datatypes::DataType; | ||
| use arrow::{array::ArrayRef, datatypes::SchemaRef, error::ArrowError}; | ||
| use datafusion_common::{Column, DataFusionError, Result}; | ||
| use datafusion_optimizer::utils::split_conjunction; | ||
| use log::{debug, error, trace}; | ||
| use parquet::schema::types::ColumnDescriptor; | ||
| use parquet::{ | ||
| arrow::arrow_reader::{RowSelection, RowSelector}, | ||
| errors::ParquetError, | ||
|
|
@@ -37,6 +40,9 @@ use std::collections::VecDeque; | |
| use std::sync::Arc; | ||
|
|
||
| use crate::physical_optimizer::pruning::{PruningPredicate, PruningStatistics}; | ||
| use crate::physical_plan::file_format::parquet::{ | ||
| from_bytes_to_i128, parquet_to_arrow_decimal_type, | ||
| }; | ||
|
|
||
| use super::metrics::ParquetFileMetrics; | ||
|
|
||
|
|
@@ -134,6 +140,7 @@ pub(crate) fn build_page_filter( | |
| &predicate, | ||
| rg_offset_indexes.get(col_id), | ||
| rg_page_indexes.get(col_id), | ||
| groups[*r].column(col_id).column_descr(), | ||
| file_metrics, | ||
| ) | ||
| .map_err(|e| { | ||
|
|
@@ -307,15 +314,18 @@ fn prune_pages_in_one_row_group( | |
| predicate: &PruningPredicate, | ||
| col_offset_indexes: Option<&Vec<PageLocation>>, | ||
| col_page_indexes: Option<&Index>, | ||
| col_desc: &ColumnDescriptor, | ||
| metrics: &ParquetFileMetrics, | ||
| ) -> Result<Vec<RowSelector>> { | ||
| let num_rows = group.num_rows() as usize; | ||
| if let (Some(col_offset_indexes), Some(col_page_indexes)) = | ||
| (col_offset_indexes, col_page_indexes) | ||
| { | ||
| let target_type = parquet_to_arrow_decimal_type(col_desc); | ||
| let pruning_stats = PagesPruningStatistics { | ||
| col_page_indexes, | ||
| col_offset_indexes, | ||
| target_type: &target_type, | ||
| }; | ||
|
|
||
| match predicate.prune(&pruning_stats) { | ||
|
|
@@ -384,6 +394,9 @@ fn create_row_count_in_each_page( | |
| struct PagesPruningStatistics<'a> { | ||
| col_page_indexes: &'a Index, | ||
| col_offset_indexes: &'a Vec<PageLocation>, | ||
| // target_type means the logical type in schema: like 'DECIMAL' is the logical type, but the | ||
|
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. 👍 |
||
| // real physical type in parquet file may be `INT32, INT64, FIXED_LEN_BYTE_ARRAY` | ||
| target_type: &'a Option<DataType>, | ||
| } | ||
|
|
||
| // Extract the min or max value calling `func` from page idex | ||
|
|
@@ -392,16 +405,50 @@ macro_rules! get_min_max_values_for_page_index { | |
| match $self.col_page_indexes { | ||
| Index::NONE => None, | ||
| Index::INT32(index) => { | ||
| let vec = &index.indexes; | ||
| Some(Arc::new(Int32Array::from_iter( | ||
| vec.iter().map(|x| x.$func().cloned()), | ||
| ))) | ||
| match $self.target_type { | ||
| // int32 to decimal with the precision and scale | ||
| Some(DataType::Decimal128(precision, scale)) => { | ||
| let vec = &index.indexes; | ||
| if let Ok(arr) = Decimal128Array::from_iter_values( | ||
| vec.iter().map(|x| *x.$func().unwrap() as i128), | ||
| ) | ||
| .with_precision_and_scale(*precision, *scale) | ||
| { | ||
| return Some(Arc::new(arr)); | ||
| } else { | ||
| return None; | ||
| } | ||
| } | ||
| _ => { | ||
| let vec = &index.indexes; | ||
| Some(Arc::new(Int32Array::from_iter( | ||
| vec.iter().map(|x| x.$func().cloned()), | ||
| ))) | ||
| } | ||
| } | ||
| } | ||
| Index::INT64(index) => { | ||
| let vec = &index.indexes; | ||
| Some(Arc::new(Int64Array::from_iter( | ||
| vec.iter().map(|x| x.$func().cloned()), | ||
| ))) | ||
| match $self.target_type { | ||
| // int64 to decimal with the precision and scale | ||
| Some(DataType::Decimal128(precision, scale)) => { | ||
| let vec = &index.indexes; | ||
| if let Ok(arr) = Decimal128Array::from_iter_values( | ||
| vec.iter().map(|x| *x.$func().unwrap() as i128), | ||
Ted-Jiang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
| .with_precision_and_scale(*precision, *scale) | ||
| { | ||
| return Some(Arc::new(arr)); | ||
| } else { | ||
| return None; | ||
| } | ||
| } | ||
| _ => { | ||
| let vec = &index.indexes; | ||
| Some(Arc::new(Int64Array::from_iter( | ||
| vec.iter().map(|x| x.$func().cloned()), | ||
| ))) | ||
| } | ||
| } | ||
| } | ||
| Index::FLOAT(index) => { | ||
| let vec = &index.indexes; | ||
|
|
@@ -430,10 +477,28 @@ macro_rules! get_min_max_values_for_page_index { | |
| .collect(); | ||
| Some(Arc::new(array)) | ||
| } | ||
| Index::INT96(_) | Index::FIXED_LEN_BYTE_ARRAY(_) => { | ||
| Index::INT96(_) => { | ||
| //Todo support these type | ||
| None | ||
| } | ||
| Index::FIXED_LEN_BYTE_ARRAY(index) => { | ||
| match $self.target_type { | ||
| // int32 to decimal with the precision and scale | ||
| Some(DataType::Decimal128(precision, scale)) => { | ||
| let vec = &index.indexes; | ||
| if let Ok(array) = Decimal128Array::from_iter_values( | ||
| vec.iter().map(|x| from_bytes_to_i128(x.$func().unwrap())), | ||
| ) | ||
| .with_precision_and_scale(*precision, *scale) | ||
| { | ||
| return Some(Arc::new(array)); | ||
| } else { | ||
| return None; | ||
| } | ||
| } | ||
| _ => None, | ||
| } | ||
| } | ||
| } | ||
| }}; | ||
| } | ||
|
|
||
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
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 |
|---|---|---|
|
|
@@ -19,8 +19,8 @@ use std::ops::Range; | |
| use std::sync::Arc; | ||
|
|
||
| use arrow::array::{ | ||
| Int32Builder, StringBuilder, StringDictionaryBuilder, TimestampNanosecondBuilder, | ||
| UInt16Builder, | ||
| Decimal128Builder, Int32Builder, StringBuilder, StringDictionaryBuilder, | ||
| TimestampNanosecondBuilder, UInt16Builder, | ||
| }; | ||
| use arrow::datatypes::{DataType, Field, Int32Type, Schema, SchemaRef, TimeUnit}; | ||
| use arrow::record_batch::RecordBatch; | ||
|
|
@@ -43,6 +43,7 @@ struct BatchBuilder { | |
| request_bytes: Int32Builder, | ||
| response_bytes: Int32Builder, | ||
| response_status: UInt16Builder, | ||
| prices_status: Decimal128Builder, | ||
|
|
||
| /// optional number of rows produced | ||
| row_limit: Option<usize>, | ||
|
|
@@ -73,6 +74,7 @@ impl BatchBuilder { | |
| Field::new("request_bytes", DataType::Int32, true), | ||
| Field::new("response_bytes", DataType::Int32, true), | ||
| Field::new("response_status", DataType::UInt16, false), | ||
| Field::new("decimal_price", DataType::Decimal128(38, 0), false), | ||
| ])) | ||
| } | ||
|
|
||
|
|
@@ -146,6 +148,7 @@ impl BatchBuilder { | |
| .append_option(rng.gen_bool(0.9).then(|| rng.gen())); | ||
| self.response_status | ||
| .append_value(status[rng.gen_range(0..status.len())]); | ||
| self.prices_status.append_value(self.row_count as i128); | ||
|
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. the incrementing price makes sense for range testing |
||
| } | ||
|
|
||
| fn finish(mut self, schema: SchemaRef) -> RecordBatch { | ||
|
|
@@ -166,6 +169,12 @@ impl BatchBuilder { | |
| Arc::new(self.request_bytes.finish()), | ||
| Arc::new(self.response_bytes.finish()), | ||
| Arc::new(self.response_status.finish()), | ||
| Arc::new( | ||
| self.prices_status | ||
| .finish() | ||
| .with_precision_and_scale(38, 0) | ||
| .unwrap(), | ||
| ), | ||
| ], | ||
| ) | ||
| .unwrap() | ||
|
|
||
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.
Move the common func here.