paleolimbot commented on code in PR #561:
URL: https://github.com/apache/sedona-db/pull/561#discussion_r2764579046


##########
rust/sedona-geoparquet/src/file_opener.rs:
##########
@@ -371,6 +453,109 @@ fn parse_column_coverings(
         .collect()
 }
 
+/// Calculates a Vec of [GeoStatistics] based on Parquet-native GeoStatistics
+///
+/// Each element is either a [GeoStatistics] populated with a [BoundingBox]
+/// or [GeoStatistics::unspecified], which is a value that will ensure that
+/// any spatial predicate that references those statistics will evaluate to
+/// true.
+fn row_group_native_geo_stats(
+    row_group_metadata: &RowGroupMetaData,
+    column_indices: &[usize],
+) -> Vec<GeoStatistics> {
+    column_indices
+        .iter()
+        .map(|column_index| {
+            let native_geo_stats_opt = 
row_group_metadata.column(*column_index).geo_statistics();
+            native_geo_stats_opt
+                .map(parquet_geo_stats_to_sedona_geo_stats)
+                .unwrap_or(GeoStatistics::unspecified())
+        })
+        .collect()
+}
+
+/// Convert Parquet [GeospatialStatistics] into Sedona [GeoStatistics]
+///
+/// This also sanity checks the Parquet statistics for non-finite or 
non-sensical
+/// ranges, treating the information as unknown if it fails the sanity check.
+fn parquet_geo_stats_to_sedona_geo_stats(
+    parquet_geo_stats: &GeospatialStatistics,
+) -> GeoStatistics {
+    let mut out = GeoStatistics::unspecified();
+
+    if let Some(native_bbox) = parquet_geo_stats.bounding_box() {
+        let x_range = (native_bbox.get_xmin(), native_bbox.get_xmax());
+        let y_range = (native_bbox.get_ymin(), native_bbox.get_ymax());
+        let z_range = match (native_bbox.get_zmin(), native_bbox.get_zmax()) {
+            (Some(lo), Some(hi)) => Some(Interval::new(lo, hi)),
+            _ => None,
+        };
+        let m_range = match (native_bbox.get_mmin(), native_bbox.get_mmax()) {
+            (Some(lo), Some(hi)) => Some(Interval::new(lo, hi)),
+            _ => None,
+        };
+
+        let bbox = BoundingBox::xyzm(x_range, y_range, z_range, m_range);
+
+        // Sanity check the bbox statistics. If the sanity check fails, don't 
set
+        // a bounding box for pruning. Note that the x width can be < 0 
(wraparound).
+        let mut bbox_is_valid =

Review Comment:
   It does...I added a test to make sure!



-- 
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]

Reply via email to