tustvold commented on code in PR #5110:
URL: https://github.com/apache/arrow-rs/pull/5110#discussion_r1405474275
##########
parquet/src/column/writer/mod.rs:
##########
@@ -703,6 +725,35 @@ impl<'a, E: ColumnValueEncoder> GenericColumnWriter<'a, E>
{
(Some(min), Some(max)) => {
update_min(&self.descr, &min, &mut
self.column_metrics.min_column_value);
update_max(&self.descr, &max, &mut
self.column_metrics.max_column_value);
+
+ // Check if min/max are still ascending/descending across pages
+ // Null pages aren't considered in this sort order
+ let null_page = (self.page_metrics.num_buffered_rows as u64)
+ == self.page_metrics.num_page_nulls;
+ if !null_page {
+ if let Some((latest_min, latest_max)) =
&self.latest_non_null_data_page_min_max
Review Comment:
```suggestion
if let Some((last_min, last_max)) =
&self.latest_non_null_data_page_min_max
```
I found this a little confusing whilst reviewing
##########
parquet/src/column/writer/mod.rs:
##########
@@ -703,6 +725,35 @@ impl<'a, E: ColumnValueEncoder> GenericColumnWriter<'a, E>
{
(Some(min), Some(max)) => {
update_min(&self.descr, &min, &mut
self.column_metrics.min_column_value);
update_max(&self.descr, &max, &mut
self.column_metrics.max_column_value);
+
+ // Check if min/max are still ascending/descending across pages
+ // Null pages aren't considered in this sort order
+ let null_page = (self.page_metrics.num_buffered_rows as u64)
+ == self.page_metrics.num_page_nulls;
+ if !null_page {
+ if let Some((latest_min, latest_max)) =
&self.latest_non_null_data_page_min_max
+ {
+ if self.data_page_boundary_ascending {
+ // If latest min/max are greater than new min/max
then not ascending anymore
+ let not_ascending = compare_greater(&self.descr,
latest_min, &min)
+ || compare_greater(&self.descr, latest_max,
&max);
+ if not_ascending {
+ self.data_page_boundary_ascending = false;
+ }
+ }
+
+ if self.data_page_boundary_descending {
+ // If new min/max are greater than latest min/max
then not descending anymore
+ let not_descending = compare_greater(&self.descr,
&min, latest_min)
+ || compare_greater(&self.descr, &max,
latest_max);
+ if not_descending {
+ self.data_page_boundary_descending = false;
+ }
+ }
+ }
+ self.latest_non_null_data_page_min_max =
Some((min.clone(), max.clone()));
+ }
Review Comment:
Whilst I think this is correct, perhaps you could just change
update_column_offset_index to instead take `Option<&ValueStatistics>`? This
would likely make the existing logic faster, and would make this logic perhaps
slightly easier to follow - it is a little surprising that boundary_order is
being updated outside of update_column_offset_index
##########
parquet/src/column/writer/mod.rs:
##########
@@ -467,6 +476,19 @@ impl<'a, E: ColumnValueEncoder> GenericColumnWriter<'a, E>
{
let metadata = self.write_column_metadata()?;
self.page_writer.close()?;
+ let boundary_order = match (
+ self.data_page_boundary_ascending,
+ self.data_page_boundary_descending,
+ ) {
+ // If the lists are composed of equal elements then will be marked
as ascending
+ // (Also the case if all pages are null pages)
+ (true, true) => BoundaryOrder::ASCENDING,
+ (true, false) => BoundaryOrder::ASCENDING,
Review Comment:
```suggestion
(true, _) => BoundaryOrder::ASCENDING,
```
##########
parquet/src/column/writer/mod.rs:
##########
@@ -228,6 +228,12 @@ pub struct GenericColumnWriter<'a, E: ColumnValueEncoder> {
// column index and offset index
column_index_builder: ColumnIndexBuilder,
offset_index_builder: OffsetIndexBuilder,
+ // Below fields used to incrementally check boundary order across data
pages
+ // We assume they are ascending/descending until proven wrong
+ data_page_boundary_ascending: bool,
+ data_page_boundary_descending: bool,
+ /// (min, max)
+ latest_non_null_data_page_min_max: Option<(E::T, E::T)>,
Review Comment:
```suggestion
last_non_null_data_page_min_max: Option<(E::T, E::T)>,
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]