alamb commented on code in PR #8524:
URL: https://github.com/apache/arrow-rs/pull/8524#discussion_r2414947215


##########
parquet/src/geospatial/statistics.rs:
##########
@@ -43,9 +43,7 @@ use crate::geospatial::bounding_box::BoundingBox;
 /// ```
 #[derive(Clone, Debug, PartialEq, Default)]
 pub struct GeospatialStatistics {
-    /// Optional bounding defining the spatial extent, where None represents a 
lack of information.

Review Comment:
   I wonder why remove these comments?



##########
parquet/src/arrow/arrow_writer/mod.rs:
##########
@@ -490,6 +498,18 @@ impl ArrowWriterOptions {
             ..self
         }
     }
+
+    /// Explicitly specify the Parquet schema to be used

Review Comment:
   this is a nice API addition I think



##########
parquet/src/geospatial/accumulator.rs:
##########
@@ -0,0 +1,385 @@
+// 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.
+
+//! This module provides implementations and traits for building 
[`GeospatialStatistics`]
+
+use std::sync::{Arc, OnceLock};
+
+use crate::{
+    basic::LogicalType, errors::ParquetError, 
geospatial::statistics::GeospatialStatistics,
+    schema::types::ColumnDescPtr,
+};
+
+/// Create a new [`GeoStatsAccumulator`] instance if `descr` represents a 
Geometry or
+/// Geography [`LogicalType`]
+///
+/// Returns a suitable [`GeoStatsAccumulator`] if `descr` represents a 
non-geospatial type
+/// or `None` otherwise.
+pub fn try_new_geo_stats_accumulator(
+    descr: &ColumnDescPtr,
+) -> Option<Box<dyn GeoStatsAccumulator>> {
+    if !matches!(
+        descr.logical_type(),
+        Some(LogicalType::Geometry { .. }) | Some(LogicalType::Geography { .. 
})
+    ) {
+        return None;
+    }
+
+    Some(
+        ACCUMULATOR_FACTORY
+            .get_or_init(|| 
Arc::new(DefaultGeoStatsAccumulatorFactory::default()))
+            .new_accumulator(descr),
+    )
+}
+
+/// Initialize the global [`GeoStatsAccumulatorFactory`]
+///
+/// This may only be done once before any calls to 
[`try_new_geo_stats_accumulator`].
+/// Clients may use this to implement support for builds of the Parquet crate 
without
+/// geospatial support or to implement support for Geography bounding using 
external
+/// dependencies.
+pub fn init_geo_stats_accumulator_factory(
+    factory: Arc<dyn GeoStatsAccumulatorFactory>,
+) -> Result<(), ParquetError> {
+    if ACCUMULATOR_FACTORY.set(factory).is_err() {
+        Err(ParquetError::General(
+            "Global GeoStatsAccumulatorFactory already set".to_string(),
+        ))
+    } else {
+        Ok(())
+    }
+}
+
+/// Global accumulator factory instance
+static ACCUMULATOR_FACTORY: OnceLock<Arc<dyn GeoStatsAccumulatorFactory>> = 
OnceLock::new();
+
+/// Factory for [`GeospatialStatistics`] accumulators
+///
+/// The GeoStatsAccumulatorFactory is a trait implemented by the global 
factory that
+/// generates new instances of a [GeoStatsAccumulator] when constructing new
+/// encoders for a Geometry or Geography logical type.
+pub trait GeoStatsAccumulatorFactory: Send + Sync {
+    /// Create a new [GeoStatsAccumulator] appropriate for the logical type of 
a given
+    /// [ColumnDescPtr]
+    fn new_accumulator(&self, descr: &ColumnDescPtr) -> Box<dyn 
GeoStatsAccumulator>;
+}
+
+/// Dynamic [`GeospatialStatistics``] accumulator

Review Comment:
   this is a nice API for optional statistics encoding



##########
parquet/Cargo.toml:
##########
@@ -131,6 +132,8 @@ flate2-rust_backened = ["flate2/rust_backend"]
 flate2-zlib-rs = ["flate2/zlib-rs"]
 # Enable parquet variant support
 variant_experimental = ["arrow", "parquet-variant", "parquet-variant-json", 
"parquet-variant-compute"]
+# Enable geospatial support
+geospatial = ["parquet-geospatial"]

Review Comment:
   Could you please also add the new feature flag to the main crate readme as 
well? 
   
   https://github.com/apache/arrow-rs/blob/main/parquet/README.md#feature-flags



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