-
Notifications
You must be signed in to change notification settings - Fork 750
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
Push gather down to Parquet Encoder #2109
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -39,7 +39,11 @@ pub trait ColumnValues { | |
/// Returns the min and max values in this collection, skipping any NaN values | ||
/// | ||
/// Returns `None` if no values found | ||
fn min_max(&self, descr: &ColumnDescriptor) -> Option<(&Self::T, &Self::T)>; | ||
fn min_max<'a>( | ||
&'a self, | ||
descr: &ColumnDescriptor, | ||
value_indices: Option<&[usize]>, | ||
) -> Option<(&'a Self::T, &'a Self::T)>; | ||
} | ||
|
||
/// The encoded data for a dictionary page | ||
|
@@ -77,6 +81,9 @@ pub trait ColumnValueEncoder { | |
/// Write the corresponding values to this [`ColumnValueEncoder`] | ||
fn write(&mut self, values: &Self::Values, offset: usize, len: usize) -> Result<()>; | ||
|
||
/// Write the corresponding values to this [`ColumnValueEncoder`] | ||
fn write_gather(&mut self, values: &Self::Values, indices: &[usize]) -> Result<()>; | ||
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. I'm not totally sold on this name, suggestions welcome |
||
|
||
/// Returns the number of buffered values | ||
fn num_values(&self) -> usize; | ||
|
||
|
@@ -148,7 +155,7 @@ impl<T: DataType> ColumnValueEncoder for ColumnValueEncoderImpl<T> { | |
) | ||
})?; | ||
|
||
if let Some((min, max)) = slice.min_max(&self.descr) { | ||
if let Some((min, max)) = slice.min_max(&self.descr, None) { | ||
update_min(&self.descr, min, &mut self.min_value); | ||
update_max(&self.descr, max, &mut self.max_value); | ||
} | ||
|
@@ -159,6 +166,20 @@ impl<T: DataType> ColumnValueEncoder for ColumnValueEncoderImpl<T> { | |
} | ||
} | ||
|
||
fn write_gather(&mut self, values: &Self::Values, indices: &[usize]) -> Result<()> { | ||
self.num_values += indices.len(); | ||
|
||
if let Some((min, max)) = values.min_max(&self.descr, Some(indices)) { | ||
update_min(&self.descr, min, &mut self.min_value); | ||
update_max(&self.descr, max, &mut self.max_value); | ||
} | ||
|
||
match &mut self.dict_encoder { | ||
Some(encoder) => encoder.put_gather(values, indices), | ||
_ => self.encoder.put_gather(values, indices), | ||
} | ||
} | ||
|
||
fn num_values(&self) -> usize { | ||
self.num_values | ||
} | ||
|
@@ -222,29 +243,42 @@ impl<T: ParquetValueType> ColumnValues for [T] { | |
self.len() | ||
} | ||
|
||
fn min_max(&self, descr: &ColumnDescriptor) -> Option<(&T, &T)> { | ||
let mut iter = self.iter(); | ||
fn min_max<'a>( | ||
&'a self, | ||
descr: &ColumnDescriptor, | ||
value_indices: Option<&[usize]>, | ||
) -> Option<(&'a T, &'a T)> { | ||
match value_indices { | ||
Some(indices) => get_min_max(descr, indices.iter().map(|x| &self[*x])), | ||
None => get_min_max(descr, self.iter()), | ||
} | ||
} | ||
} | ||
|
||
let first = loop { | ||
let next = iter.next()?; | ||
if !is_nan(next) { | ||
break next; | ||
} | ||
}; | ||
fn get_min_max<'a, T, I>(descr: &ColumnDescriptor, mut iter: I) -> Option<(&'a T, &'a T)> | ||
where | ||
T: ParquetValueType, | ||
I: Iterator<Item = &'a T>, | ||
{ | ||
let first = loop { | ||
let next = iter.next()?; | ||
if !is_nan(next) { | ||
break next; | ||
} | ||
}; | ||
|
||
let mut min = first; | ||
let mut max = first; | ||
for val in iter { | ||
if is_nan(val) { | ||
continue; | ||
} | ||
if compare_greater(descr, min, val) { | ||
min = val; | ||
} | ||
if compare_greater(descr, val, max) { | ||
max = val; | ||
} | ||
let mut min = first; | ||
let mut max = first; | ||
for val in iter { | ||
if is_nan(val) { | ||
continue; | ||
} | ||
if compare_greater(descr, min, val) { | ||
min = val; | ||
} | ||
if compare_greater(descr, val, max) { | ||
max = val; | ||
} | ||
Some((min, max)) | ||
} | ||
Some((min, max)) | ||
} |
This file contains 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
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.
This if statement was somewhat redundant, I suspect it dates from a refactor at some point