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


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

Review Comment:
   ```suggestion
   /// generates new instances of a [`GeoStatsAccumulator`] when constructing 
new
   ```



##########
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
+///
+/// The GeoStatsAccumulator is a trait whose implementors can ingest the 
(non-null)
+/// elements of a column and return compliant [`GeospatialStatistics`] (or 
`None`).
+/// When built with geospatial support this will usually be the
+/// [ParquetGeoStatsAccumulator]
+pub trait GeoStatsAccumulator: Send {
+    /// Returns true if this instance can return [`GeospatialStatistics`] from
+    /// [GeoStatsAccumulator::finish].

Review Comment:
   ```suggestion
       /// [`GeoStatsAccumulator::finish`].
   ```



##########
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
+///
+/// The GeoStatsAccumulator is a trait whose implementors can ingest the 
(non-null)
+/// elements of a column and return compliant [`GeospatialStatistics`] (or 
`None`).
+/// When built with geospatial support this will usually be the
+/// [ParquetGeoStatsAccumulator]
+pub trait GeoStatsAccumulator: Send {
+    /// Returns true if this instance can return [`GeospatialStatistics`] from
+    /// [GeoStatsAccumulator::finish].
+    ///
+    /// This method returns false when this crate was built without geospatial 
support
+    /// (i.e., from the [VoidGeoStatsAccumulator]) or if the accumulator 
encountered
+    /// invalid or unsupported elements for which it cannot compute valid 
statistics.
+    fn is_valid(&self) -> bool;
+
+    /// Update with a single slice of WKB-encoded values
+    ///
+    /// This method is infallible; however, in the event of improperly encoded 
values,
+    /// implementations must ensure that [GeoStatsAccumulator::finish] returns 
`None`.
+    fn update_wkb(&mut self, wkb: &[u8]);
+
+    /// Compute the final statistics and reset internal state
+    fn finish(&mut self) -> Option<Box<GeospatialStatistics>>;
+}
+
+/// Default accumulator for [`GeospatialStatistics`]
+///
+/// When this crate was built with geospatial support, this factory constructs 
a
+/// [ParquetGeoStatsAccumulator] that ensures Geometry columns are written with
+/// statistics when statistics for that column are enabled. Otherwise, this 
factory
+/// returns a [`VoidGeoStatsAccumulator`] that never adds any geospatial 
statistics.
+///
+/// Bounding for Geography columns is not currently implemented by 
parquet-geospatial
+/// and this factory will always return a [`VoidGeoStatsAccumulator`].
+#[derive(Debug, Default)]
+pub struct DefaultGeoStatsAccumulatorFactory {}
+
+impl GeoStatsAccumulatorFactory for DefaultGeoStatsAccumulatorFactory {
+    fn new_accumulator(&self, _descr: &ColumnDescPtr) -> Box<dyn 
GeoStatsAccumulator> {
+        #[cfg(feature = "geospatial")]
+        if let Some(crate::basic::LogicalType::Geometry { .. }) = 
_descr.logical_type() {
+            Box::new(ParquetGeoStatsAccumulator::default())
+        } else {
+            Box::new(VoidGeoStatsAccumulator::default())
+        }
+
+        #[cfg(not(feature = "geospatial"))]
+        return Box::new(VoidGeoStatsAccumulator::default());
+    }
+}
+
+/// A [`GeoStatsAccumulator`] that never computes any [`GeospatialStatistics`]
+#[derive(Debug, Default)]
+pub struct VoidGeoStatsAccumulator {}
+
+impl GeoStatsAccumulator for VoidGeoStatsAccumulator {
+    fn is_valid(&self) -> bool {
+        false
+    }
+
+    fn update_wkb(&mut self, _wkb: &[u8]) {}
+
+    fn finish(&mut self) -> Option<Box<GeospatialStatistics>> {
+        None
+    }
+}
+
+/// A [GeoStatsAccumulator] that uses the parquet-geospatial crate to compute 
Geometry statistics

Review Comment:
   ```suggestion
   /// A [`GeoStatsAccumulator`] that uses the parquet-geospatial crate to 
compute Geometry statistics
   ```



##########
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
+///
+/// The GeoStatsAccumulator is a trait whose implementors can ingest the 
(non-null)
+/// elements of a column and return compliant [`GeospatialStatistics`] (or 
`None`).
+/// When built with geospatial support this will usually be the
+/// [ParquetGeoStatsAccumulator]
+pub trait GeoStatsAccumulator: Send {
+    /// Returns true if this instance can return [`GeospatialStatistics`] from
+    /// [GeoStatsAccumulator::finish].
+    ///
+    /// This method returns false when this crate was built without geospatial 
support
+    /// (i.e., from the [VoidGeoStatsAccumulator]) or if the accumulator 
encountered
+    /// invalid or unsupported elements for which it cannot compute valid 
statistics.
+    fn is_valid(&self) -> bool;
+
+    /// Update with a single slice of WKB-encoded values
+    ///
+    /// This method is infallible; however, in the event of improperly encoded 
values,
+    /// implementations must ensure that [GeoStatsAccumulator::finish] returns 
`None`.

Review Comment:
   ```suggestion
       /// implementations must ensure that [`GeoStatsAccumulator::finish`] 
returns `None`.
   ```



##########
parquet-geospatial/src/testing.rs:
##########
@@ -0,0 +1,66 @@
+// 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.
+
+//! Testing utilities for geospatial Parquet types
+
+/// Build well-known binary representing a point with the given XY coordinate
+pub fn wkb_point_xy(x: f64, y: f64) -> Vec<u8> {

Review Comment:
   Will these eventually be used or are they intended to help users?



##########
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:
   ```suggestion
   /// Dynamic [`GeospatialStatistics`] accumulator
   ```



##########
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
+///
+/// The GeoStatsAccumulator is a trait whose implementors can ingest the 
(non-null)
+/// elements of a column and return compliant [`GeospatialStatistics`] (or 
`None`).
+/// When built with geospatial support this will usually be the
+/// [ParquetGeoStatsAccumulator]
+pub trait GeoStatsAccumulator: Send {
+    /// Returns true if this instance can return [`GeospatialStatistics`] from
+    /// [GeoStatsAccumulator::finish].
+    ///
+    /// This method returns false when this crate was built without geospatial 
support
+    /// (i.e., from the [VoidGeoStatsAccumulator]) or if the accumulator 
encountered
+    /// invalid or unsupported elements for which it cannot compute valid 
statistics.
+    fn is_valid(&self) -> bool;
+
+    /// Update with a single slice of WKB-encoded values
+    ///
+    /// This method is infallible; however, in the event of improperly encoded 
values,
+    /// implementations must ensure that [GeoStatsAccumulator::finish] returns 
`None`.
+    fn update_wkb(&mut self, wkb: &[u8]);
+
+    /// Compute the final statistics and reset internal state
+    fn finish(&mut self) -> Option<Box<GeospatialStatistics>>;
+}
+
+/// Default accumulator for [`GeospatialStatistics`]
+///
+/// When this crate was built with geospatial support, this factory constructs 
a
+/// [ParquetGeoStatsAccumulator] that ensures Geometry columns are written with

Review Comment:
   ```suggestion
   /// When this crate is built with geospatial support, this factory 
constructs a
   /// [`ParquetGeoStatsAccumulator`] that ensures Geometry columns are written 
with
   ```



##########
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
+///
+/// The GeoStatsAccumulator is a trait whose implementors can ingest the 
(non-null)
+/// elements of a column and return compliant [`GeospatialStatistics`] (or 
`None`).
+/// When built with geospatial support this will usually be the
+/// [ParquetGeoStatsAccumulator]
+pub trait GeoStatsAccumulator: Send {
+    /// Returns true if this instance can return [`GeospatialStatistics`] from
+    /// [GeoStatsAccumulator::finish].
+    ///
+    /// This method returns false when this crate was built without geospatial 
support
+    /// (i.e., from the [VoidGeoStatsAccumulator]) or if the accumulator 
encountered

Review Comment:
   ```suggestion
       /// This method returns false when this crate id built without 
geospatial support
       /// (i.e., from the [`VoidGeoStatsAccumulator`]) or if the accumulator 
encountered
   ```



##########
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
+///
+/// The GeoStatsAccumulator is a trait whose implementors can ingest the 
(non-null)
+/// elements of a column and return compliant [`GeospatialStatistics`] (or 
`None`).
+/// When built with geospatial support this will usually be the
+/// [ParquetGeoStatsAccumulator]

Review Comment:
   ```suggestion
   /// [`ParquetGeoStatsAccumulator`]
   ```



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

Review Comment:
   ```suggestion
       /// Create a new [`GeoStatsAccumulator`] appropriate for the logical 
type of a given
       /// [`ColumnDescPtr`]
   ```



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