You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/06/05 09:18:42 UTC

[GitHub] [arrow-rs] tustvold commented on a diff in pull request #1791: feat:Implement page filtering with Row Alignment

tustvold commented on code in PR #1791:
URL: https://github.com/apache/arrow-rs/pull/1791#discussion_r889668210


##########
parquet/src/file/metadata.rs:
##########
@@ -223,6 +223,7 @@ pub struct RowGroupMetaData {
     num_rows: i64,
     total_byte_size: i64,
     schema_descr: SchemaDescPtr,
+    // Todo add filter result -> row range

Review Comment:
   The more I think about this the more I wonder whether the metadata structs are the right place to put the index information. They're parsed and interpreted separately from the main metadata, and so I think it makes sense for them to be stored separately?



##########
parquet/src/file/page_index/range.rs:
##########
@@ -0,0 +1,472 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+use crate::errors::ParquetError;
+use parquet_format::PageLocation;
+use std::cmp::Ordering;
+use std::collections::VecDeque;
+
+/// A row range
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
+pub struct Range {
+    /// Its start
+    pub from: usize,
+    /// Its end
+    pub to: usize,
+}
+
+impl Range {
+    // Creates a range of [from, to] (from and to are both inclusive)

Review Comment:
   I'm curious why you opted for inclusive ranges, when exclusive ranges better match the source data and are more common in Rust



##########
parquet/src/file/page_index/mod.rs:
##########
@@ -17,3 +17,4 @@
 
 pub mod index;
 pub mod index_reader;
+pub mod range;

Review Comment:
   At least whilst we're still iterating on these APIs perhaps `pub(crate)`



##########
parquet/src/file/page_index/range.rs:
##########
@@ -0,0 +1,472 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+use crate::errors::ParquetError;
+use parquet_format::PageLocation;
+use std::cmp::Ordering;
+use std::collections::VecDeque;
+
+/// A row range
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
+pub struct Range {
+    /// Its start
+    pub from: usize,
+    /// Its end
+    pub to: usize,
+}
+
+impl Range {
+    // Creates a range of [from, to] (from and to are both inclusive)
+    pub fn new(from: usize, to: usize) -> Self {
+        assert!(from <= to);
+        Self { from, to }
+    }
+
+    pub fn count(&self) -> usize {
+        self.to - self.from + 1
+    }
+
+    pub fn is_before(&self, other: &Range) -> bool {
+        self.to < other.from
+    }
+
+    pub fn is_after(&self, other: &Range) -> bool {
+        self.from > other.to
+    }
+
+    /// Return the union of the two ranges,
+    /// Return `None` if there are hole between them.
+    pub fn union(left: &Range, right: &Range) -> Option<Range> {
+        if left.from <= right.from {
+            if left.to + 1 >= right.from {
+                return Some(Range {
+                    from: left.from,
+                    to: std::cmp::max(left.to, right.to),
+                });
+            }
+        } else if right.to + 1 >= left.from {
+            return Some(Range {
+                from: right.from,
+                to: std::cmp::max(left.to, right.to),
+            });
+        }
+        None
+    }
+
+    /// Returns the intersection of the two ranges,
+    /// return null if they are not overlapped.
+    pub fn intersection(left: &Range, right: &Range) -> Option<Range> {
+        if left.from <= right.from {
+            if left.to >= right.from {
+                return Some(Range {
+                    from: right.from,
+                    to: std::cmp::min(left.to, right.to),
+                });
+            }
+        } else if right.to >= left.from {
+            return Some(Range {
+                from: left.from,
+                to: std::cmp::min(left.to, right.to),
+            });
+        }
+        None
+    }
+}
+
+/// Struct representing row ranges in a row-group. These row ranges are calculated as a result of using
+/// the column index on the filtering.
+#[derive(Debug, Clone)]
+pub struct RowRanges {

Review Comment:
   I think this data structure is typically called am IntervalSet. There might even be an upstream crate implementation... 🤔



##########
parquet/src/file/page_index/range.rs:
##########
@@ -0,0 +1,472 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+use crate::errors::ParquetError;
+use parquet_format::PageLocation;
+use std::cmp::Ordering;
+use std::collections::VecDeque;
+
+/// A row range
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
+pub struct Range {
+    /// Its start

Review Comment:
   Is there a particular reason you opted to not use std::ops:RangeInclusive. Potentially with free functions or am extension trait for the intersection, union, etc... ?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org