You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@sedona.apache.org by "CaptainAni187 (via GitHub)" <gi...@apache.org> on 2026/10/19 21:21:33 UTC
[PR] feat(c/sedona-geos): implement ST_Union_Agg with GEOS [sedona-db]
CaptainAni187 opened a new pull request, #1468:
URL: https://github.com/apache/sedona-db/pull/1468
Part of #1459 (ST_Union_Agg only, ST_Intersection_Agg is left for a separate PR).
Moves `ST_Union_Agg` to GEOS so it handles every geometry type. The accumulator follows `ST_Polygonize_Agg`: it collects the inputs into one geometry collection and runs a single GEOS `unary_union` when the result is evaluated. A point or linestring is no longer dropped when it comes first or rejected when it comes after a polygon, so the result doesn't depend on row order anymore. NULL inputs are skipped and no input gives NULL, same as before.
As discussed on the issue, the `sedona-geo` version is removed, since its aggregate kernels are registered after GEOS and would otherwise still win. Its benchmark moves to `c/sedona-geos/benches`.
On buffering vs union per geometry: on the `Array(Polygon(10))` aggregate benchmark the buffered `unary_union` takes about 3.0 s and union per geometry about 108 s. For 2000 overlapping squares it's 73 ms vs 6.5 s, with the same result, so this keeps the buffered approach.
One behaviour change worth knowing about: a union that comes out as a single polygon is now a `POLYGON` (like PostGIS) instead of always a `MULTIPOLYGON`.
The workaround in `sedonadb-geopandas` `dissolve()` that avoids ST_Union_Agg because of #1093 could probably be dropped now, but I left it for a follow-up.
--
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: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(c/sedona-geos): implement ST_Union_Agg with GEOS [sedona-db]
Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu commented on code in PR #1468:
URL: https://github.com/apache/sedona-db/pull/1468#discussion_r4320449202
##########
c/sedona-geos/src/st_union_agg.rs:
##########
@@ -0,0 +1,279 @@
+// 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 std::sync::Arc;
+
+use crate::wkb_to_geos::GEOSWkbFactory;
+use arrow_array::{cast::AsArray, types::UInt64Type, Array, ArrayRef};
+use arrow_schema::{DataType, Field, FieldRef};
+use datafusion_common::{cast::as_binary_array, error::Result, DataFusionError, ScalarValue};
+use datafusion_expr::{Accumulator, ColumnarValue};
+use geo_traits::Dimensions;
+use geos::Geom;
+use sedona_common::sedona_internal_err;
+use sedona_expr::{
+ aggregate_udf::{SedonaAccumulator, SedonaAccumulatorRef},
+ item_crs::ItemCrsSedonaAccumulator,
+};
+use sedona_geometry::wkb_factory::write_wkb_geometrycollection_header;
+use sedona_schema::{
+ datatypes::{SedonaType, WKB_GEOMETRY},
+ matchers::ArgMatcher,
+};
+use wkb::reader::read_wkb;
+
+/// ST_Union_Agg() aggregate implementation using GEOS
+pub fn st_union_agg_impl() -> Vec<SedonaAccumulatorRef> {
+ ItemCrsSedonaAccumulator::wrap_impl(STUnionAgg {})
+}
+
+#[derive(Debug)]
+struct STUnionAgg {}
+
+impl SedonaAccumulator for STUnionAgg {
+ fn return_type(&self, args: &[SedonaType]) -> Result<Option<SedonaType>> {
+ let matcher = ArgMatcher::new(vec![ArgMatcher::is_geometry()], WKB_GEOMETRY);
+ matcher.match_args(args)
+ }
+
+ fn accumulator(
+ &self,
+ args: &[SedonaType],
+ _output_type: &SedonaType,
+ ) -> Result<Box<dyn Accumulator>> {
+ Ok(Box::new(UnionAccumulator::new(args[0].clone())))
+ }
+
+ fn state_fields(&self, _args: &[SedonaType]) -> Result<Vec<FieldRef>> {
+ Ok(vec![
+ Arc::new(Field::new("count", DataType::UInt64, false)),
+ Arc::new(Field::new("item", DataType::Binary, true)),
+ ])
+ }
+}
+
+#[derive(Debug)]
+struct UnionAccumulator {
+ input_type: SedonaType,
+ item: Vec<u8>,
+ count: usize,
+}
+
+const WKB_HEADER_SIZE: usize = 1 + 4 + 4;
+
+fn empty_collection() -> Vec<u8> {
+ let mut item = Vec::new();
+ write_wkb_geometrycollection_header(&mut item, Dimensions::Xy, 0)
+ .expect("Failed to write initial GeometryCollection header");
+ item
+}
+
+impl UnionAccumulator {
+ fn new(input_type: SedonaType) -> Self {
+ Self {
+ input_type,
+ item: empty_collection(),
+ count: 0,
+ }
+ }
+
+ fn make_wkb_result(&mut self) -> Result<Option<Vec<u8>>> {
+ if self.count == 0 {
+ return Ok(None);
+ }
+
+ let mut header = Vec::new();
+ write_wkb_geometrycollection_header(&mut header, Dimensions::Xy, self.count)
+ .map_err(|e| DataFusionError::Execution(format!("Failed to write header: {e}")))?;
+ self.item[0..WKB_HEADER_SIZE].copy_from_slice(&header);
+
+ let wkb = read_wkb(&self.item)
+ .map_err(|e| DataFusionError::Execution(format!("Failed to read WKB: {e}")))?;
+ let collection = GEOSWkbFactory::new().create(&wkb).map_err(|e| {
+ DataFusionError::Execution(format!("Failed to create geometry from WKB: {e}"))
+ })?;
+ let union = collection
+ .unary_union()
+ .map_err(|e| DataFusionError::Execution(format!("Failed to compute union: {e}")))?;
+ let wkb = union.to_wkb().map_err(|e| {
Review Comment:
Could we use `write_geos_geometry` here, like `ST_UnaryUnion` does? Even a single point loses its Z coordinate:
```sql
SELECT ST_AsText(ST_Union_Agg(geom))
FROM (VALUES (ST_GeomFromText('POINT Z (1 2 3)'))) AS t(geom);
-- expected: POINT Z (1 2 3)
-- actual: POINT (1 2)
```
I reproduced this in a local aggregate test. GEOS keeps Z through the union, but `.to_wkb()` uses its default 2D output. Writing the same union with `write_geos_geometry` preserved `POINT Z (1 2 3)`.
--
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: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(c/sedona-geos): implement ST_Union_Agg with GEOS [sedona-db]
Posted by "CaptainAni187 (via GitHub)" <gi...@apache.org>.
CaptainAni187 commented on PR #1468:
URL: https://github.com/apache/sedona-db/pull/1468#issuecomment-6427691496
@paleolimbot thanks! Pushed an update:
- Added Python tests in test_aggregate.py: Z inputs, EMPTY inputs, mixed dimensions, all NULL / zero rows, and ST_Union_Agg vs ST_UnaryUnion(ST_Collect_Agg()) for 1, 7 and 2000 groups (and no GROUP BY) with XY, ST_Force3D and ST_Force4D input.
- EMPTY inputs are now tracked separately and left out of the union. If every input is EMPTY it returns an EMPTY of the highest input type, which is what PostGIS ST_Union does (e.g. POLYGON Z EMPTY + POINT Z EMPTY gives POLYGON EMPTY). Before it gave POINT EMPTY for that one.
- The types and dimensions of the non-empty inputs go into the state now, and mixed dimensions error like ST_Collect_Agg does (PostGIS errors there too). Before, a 2D point next to a Z point came out with a made up Z.
Also the Rust tests were failing on CI's GEOS 3.12 because of vertex order, they compare normalized geometries now. And sounds good on the incremental union follow up.
--
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: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(c/sedona-geos): implement ST_Union_Agg with GEOS [sedona-db]
Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu commented on code in PR #1468:
URL: https://github.com/apache/sedona-db/pull/1468#discussion_r4409028752
##########
c/sedona-geos/src/st_union_agg.rs:
##########
@@ -0,0 +1,515 @@
+// 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 std::sync::Arc;
+
+use crate::{geos_to_wkb::write_geos_geometry, wkb_to_geos::GEOSWkbFactory};
+use arrow_array::{
+ cast::AsArray,
+ types::{UInt32Type, UInt64Type},
+ Array, ArrayRef,
+};
+use arrow_schema::{DataType, Field, FieldRef};
+use datafusion_common::{
+ cast::as_binary_array, error::Result, exec_err, DataFusionError, ScalarValue,
+};
+use datafusion_expr::{Accumulator, ColumnarValue};
+use geo_traits::{
+ Dimensions, GeometryCollectionTrait, GeometryTrait, GeometryType, LineStringTrait,
+ MultiLineStringTrait, MultiPointTrait, MultiPolygonTrait, PointTrait, PolygonTrait,
+};
+use geos::Geom;
+use sedona_common::sedona_internal_err;
+use sedona_expr::{
+ aggregate_udf::{SedonaAccumulator, SedonaAccumulatorRef},
+ item_crs::ItemCrsSedonaAccumulator,
+};
+use sedona_geometry::{
+ types::{GeometryTypeAndDimensions, GeometryTypeAndDimensionsSet, GeometryTypeId},
+ wkb_factory::{
+ write_wkb_empty_point, write_wkb_geometrycollection_header, write_wkb_linestring_header,
+ write_wkb_multilinestring_header, write_wkb_multipoint_header,
+ write_wkb_multipolygon_header, write_wkb_polygon_header,
+ },
+};
+use sedona_schema::{
+ datatypes::{SedonaType, WKB_GEOMETRY},
+ matchers::ArgMatcher,
+};
+use wkb::reader::read_wkb;
+
+/// ST_Union_Agg() aggregate implementation using GEOS
+pub fn st_union_agg_impl() -> Vec<SedonaAccumulatorRef> {
+ ItemCrsSedonaAccumulator::wrap_impl(STUnionAgg {})
+}
+
+#[derive(Debug)]
+struct STUnionAgg {}
+
+impl SedonaAccumulator for STUnionAgg {
+ fn return_type(&self, args: &[SedonaType]) -> Result<Option<SedonaType>> {
+ let matcher = ArgMatcher::new(vec![ArgMatcher::is_geometry()], WKB_GEOMETRY);
+ matcher.match_args(args)
+ }
+
+ fn accumulator(
+ &self,
+ args: &[SedonaType],
+ _output_type: &SedonaType,
+ ) -> Result<Box<dyn Accumulator>> {
+ Ok(Box::new(UnionAccumulator::new(args[0].clone())))
+ }
+
+ fn state_fields(&self, _args: &[SedonaType]) -> Result<Vec<FieldRef>> {
+ Ok(vec![
+ Arc::new(Field::new("types_and_dims", DataType::UInt32, false)),
+ Arc::new(Field::new("empty_types", DataType::UInt32, false)),
+ Arc::new(Field::new("count", DataType::UInt64, false)),
+ Arc::new(Field::new("item", DataType::Binary, true)),
+ ])
+ }
+}
+
+#[derive(Debug)]
+struct UnionAccumulator {
+ input_type: SedonaType,
+ types_and_dims: GeometryTypeAndDimensionsSet,
+ empty_types: GeometryTypeAndDimensionsSet,
+ item: Vec<u8>,
+ count: usize,
+}
+
+const WKB_HEADER_SIZE: usize = 1 + 4 + 4;
+
+fn is_empty_recursive(geometry: &impl GeometryTrait<T = f64>) -> bool {
+ match geometry.as_type() {
+ GeometryType::Point(point) => point.coord().is_none(),
+ GeometryType::LineString(line_string) => line_string.num_coords() == 0,
+ GeometryType::Polygon(polygon) => is_polygon_empty(polygon),
+ GeometryType::MultiPoint(multi_point) => {
+ multi_point.points().all(|point| point.coord().is_none())
+ }
+ GeometryType::MultiLineString(multi_line_string) => multi_line_string
+ .line_strings()
+ .all(|line_string| line_string.num_coords() == 0),
+ GeometryType::MultiPolygon(multi_polygon) => multi_polygon
+ .polygons()
+ .all(|polygon| is_polygon_empty(&polygon)),
+ GeometryType::GeometryCollection(collection) => collection
+ .geometries()
+ .all(|member| is_empty_recursive(&member)),
+ _ => false,
+ }
+}
+
+fn is_polygon_empty(polygon: &impl PolygonTrait<T = f64>) -> bool {
+ polygon.num_interiors() == 0
+ && polygon
+ .exterior()
+ .is_none_or(|exterior| exterior.num_coords() == 0)
+}
+
+fn empty_collection() -> Vec<u8> {
+ let mut item = Vec::new();
+ write_wkb_geometrycollection_header(&mut item, Dimensions::Xy, 0)
+ .expect("Failed to write initial GeometryCollection header");
+ item
+}
+
+impl UnionAccumulator {
+ fn new(input_type: SedonaType) -> Self {
+ Self {
+ input_type,
+ types_and_dims: GeometryTypeAndDimensionsSet::new(),
+ empty_types: GeometryTypeAndDimensionsSet::new(),
+ item: empty_collection(),
+ count: 0,
+ }
+ }
+
+ fn make_wkb_result(&mut self) -> Result<Option<Vec<u8>>> {
+ if self.count == 0 {
+ return self.make_empty_result();
+ }
+
+ let unique_dimensions = self.types_and_dims.dimensions();
+ if unique_dimensions.len() != 1 {
+ return exec_err!("Can't ST_Union_Agg() mixed dimension geometries");
+ }
+
+ let mut header = Vec::new();
+ write_wkb_geometrycollection_header(&mut header, unique_dimensions[0], self.count)
+ .map_err(|e| DataFusionError::Execution(format!("Failed to write header: {e}")))?;
+ self.item[0..WKB_HEADER_SIZE].copy_from_slice(&header);
+
+ let wkb = read_wkb(&self.item)
+ .map_err(|e| DataFusionError::Execution(format!("Failed to read WKB: {e}")))?;
+ let collection = GEOSWkbFactory::new().create(&wkb).map_err(|e| {
+ DataFusionError::Execution(format!("Failed to create geometry from WKB: {e}"))
+ })?;
+ let union = collection
+ .unary_union()
Review Comment:
This looks like a huge performance regression for overlapping or duplicate polygons compared with the Rust implementation this PR replaces. I benchmarked both implementations in the same release binary (M1 Max, GEOS 3.14.1, median of 7 samples):
| 2,000 unit squares | Existing Rust | This PR |
| --- | ---: | ---: |
| Overlapping, shifted by 0.25 along X | 3.44 ms | 30.78 ms (~9x slower) |
| All identical | 2.36 ms | 18.75 ms (~8x slower) |
| Disjoint, spaced by 2 on a grid | 1,586 ms | 73.74 ms (~21.5x faster) |
These time accumulator creation + update + evaluation on prebuilt WKB, excluding input construction and SQL overhead. Results were topologically equivalent. The comparison in the PR description is buffered GEOS vs incremental GEOS; this compares against the removed `sedona-geo` implementation.
Here's the overlapping input/query:
```python
import pyarrow as pa
import sedonadb
sd = sedonadb.connect()
def square(x, y):
return f"POLYGON (({x} {y}, {x+1} {y}, {x+1} {y+1}, {x} {y+1}, {x} {y}))"
wkts = [square(i / 4, 0) for i in range(2000)]
sd.create_data_frame(pa.table({"wkt": wkts})).to_view("input")
geoms = sd.sql("SELECT ST_GeomFromText(wkt) AS geom FROM input").to_arrow_table()
sd.create_data_frame(geoms).to_view("squares")
sd.sql("SELECT ST_Union_Agg(geom) FROM squares").to_arrow_table()
```
For duplicates, use `[square(0, 0)] * 2000`; for disjoint squares, use `[square(2 * (i % 50), 2 * (i // 50)) for i in range(2000)]`. The overlapping/duplicate cases also retain about 209 KB of accumulator state instead of 304 bytes, before GEOS evaluation; that's buffer capacity, not peak memory.
The latest empty-geometry fix itself looks fine. I'm not sure what to do about this broader tradeoff, given the big gain on disjoint inputs and the added geometry support. Could we add the existing Rust implementation to the benchmark comparison and discuss whether we're comfortable with this regression?
--
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: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(c/sedona-geos): implement ST_Union_Agg with GEOS [sedona-db]
Posted by "CaptainAni187 (via GitHub)" <gi...@apache.org>.
CaptainAni187 commented on code in PR #1468:
URL: https://github.com/apache/sedona-db/pull/1468#discussion_r4382666693
##########
c/sedona-geos/src/st_union_agg.rs:
##########
@@ -0,0 +1,279 @@
+// 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 std::sync::Arc;
+
+use crate::wkb_to_geos::GEOSWkbFactory;
+use arrow_array::{cast::AsArray, types::UInt64Type, Array, ArrayRef};
+use arrow_schema::{DataType, Field, FieldRef};
+use datafusion_common::{cast::as_binary_array, error::Result, DataFusionError, ScalarValue};
+use datafusion_expr::{Accumulator, ColumnarValue};
+use geo_traits::Dimensions;
+use geos::Geom;
+use sedona_common::sedona_internal_err;
+use sedona_expr::{
+ aggregate_udf::{SedonaAccumulator, SedonaAccumulatorRef},
+ item_crs::ItemCrsSedonaAccumulator,
+};
+use sedona_geometry::wkb_factory::write_wkb_geometrycollection_header;
+use sedona_schema::{
+ datatypes::{SedonaType, WKB_GEOMETRY},
+ matchers::ArgMatcher,
+};
+use wkb::reader::read_wkb;
+
+/// ST_Union_Agg() aggregate implementation using GEOS
+pub fn st_union_agg_impl() -> Vec<SedonaAccumulatorRef> {
+ ItemCrsSedonaAccumulator::wrap_impl(STUnionAgg {})
+}
+
+#[derive(Debug)]
+struct STUnionAgg {}
+
+impl SedonaAccumulator for STUnionAgg {
+ fn return_type(&self, args: &[SedonaType]) -> Result<Option<SedonaType>> {
+ let matcher = ArgMatcher::new(vec![ArgMatcher::is_geometry()], WKB_GEOMETRY);
+ matcher.match_args(args)
+ }
+
+ fn accumulator(
+ &self,
+ args: &[SedonaType],
+ _output_type: &SedonaType,
+ ) -> Result<Box<dyn Accumulator>> {
+ Ok(Box::new(UnionAccumulator::new(args[0].clone())))
+ }
+
+ fn state_fields(&self, _args: &[SedonaType]) -> Result<Vec<FieldRef>> {
+ Ok(vec![
+ Arc::new(Field::new("count", DataType::UInt64, false)),
+ Arc::new(Field::new("item", DataType::Binary, true)),
+ ])
+ }
+}
+
+#[derive(Debug)]
+struct UnionAccumulator {
+ input_type: SedonaType,
+ item: Vec<u8>,
+ count: usize,
+}
+
+const WKB_HEADER_SIZE: usize = 1 + 4 + 4;
+
+fn empty_collection() -> Vec<u8> {
+ let mut item = Vec::new();
+ write_wkb_geometrycollection_header(&mut item, Dimensions::Xy, 0)
+ .expect("Failed to write initial GeometryCollection header");
+ item
+}
+
+impl UnionAccumulator {
+ fn new(input_type: SedonaType) -> Self {
+ Self {
+ input_type,
+ item: empty_collection(),
+ count: 0,
+ }
+ }
+
+ fn make_wkb_result(&mut self) -> Result<Option<Vec<u8>>> {
+ if self.count == 0 {
+ return Ok(None);
+ }
+
+ let mut header = Vec::new();
+ write_wkb_geometrycollection_header(&mut header, Dimensions::Xy, self.count)
+ .map_err(|e| DataFusionError::Execution(format!("Failed to write header: {e}")))?;
+ self.item[0..WKB_HEADER_SIZE].copy_from_slice(&header);
+
+ let wkb = read_wkb(&self.item)
+ .map_err(|e| DataFusionError::Execution(format!("Failed to read WKB: {e}")))?;
+ let collection = GEOSWkbFactory::new().create(&wkb).map_err(|e| {
+ DataFusionError::Execution(format!("Failed to create geometry from WKB: {e}"))
+ })?;
+ let union = collection
+ .unary_union()
+ .map_err(|e| DataFusionError::Execution(format!("Failed to compute union: {e}")))?;
+ let wkb = union.to_wkb().map_err(|e| {
Review Comment:
Thanks, switched to write_geos_geometry, so POINT Z (1 2 3) comes back as POINT Z (1 2 3) now (and ZM/M are kept too). Added tests for it.
--
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: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(c/sedona-geos): implement ST_Union_Agg with GEOS [sedona-db]
Posted by "CaptainAni187 (via GitHub)" <gi...@apache.org>.
CaptainAni187 commented on code in PR #1468:
URL: https://github.com/apache/sedona-db/pull/1468#discussion_r4401799338
##########
c/sedona-geos/src/st_union_agg.rs:
##########
@@ -0,0 +1,467 @@
+// 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 std::sync::Arc;
+
+use crate::{geos_to_wkb::write_geos_geometry, wkb_to_geos::GEOSWkbFactory};
+use arrow_array::{
+ cast::AsArray,
+ types::{UInt32Type, UInt64Type},
+ Array, ArrayRef,
+};
+use arrow_schema::{DataType, Field, FieldRef};
+use datafusion_common::{
+ cast::as_binary_array, error::Result, exec_err, DataFusionError, ScalarValue,
+};
+use datafusion_expr::{Accumulator, ColumnarValue};
+use geo_traits::Dimensions;
+use geos::Geom;
+use sedona_common::sedona_internal_err;
+use sedona_expr::{
+ aggregate_udf::{SedonaAccumulator, SedonaAccumulatorRef},
+ item_crs::ItemCrsSedonaAccumulator,
+};
+use sedona_geometry::{
+ is_empty::is_geometry_empty,
+ types::{GeometryTypeAndDimensions, GeometryTypeAndDimensionsSet, GeometryTypeId},
+ wkb_factory::{
+ write_wkb_empty_point, write_wkb_geometrycollection_header, write_wkb_linestring_header,
+ write_wkb_multilinestring_header, write_wkb_multipoint_header,
+ write_wkb_multipolygon_header, write_wkb_polygon_header,
+ },
+};
+use sedona_schema::{
+ datatypes::{SedonaType, WKB_GEOMETRY},
+ matchers::ArgMatcher,
+};
+use wkb::reader::read_wkb;
+
+/// ST_Union_Agg() aggregate implementation using GEOS
+pub fn st_union_agg_impl() -> Vec<SedonaAccumulatorRef> {
+ ItemCrsSedonaAccumulator::wrap_impl(STUnionAgg {})
+}
+
+#[derive(Debug)]
+struct STUnionAgg {}
+
+impl SedonaAccumulator for STUnionAgg {
+ fn return_type(&self, args: &[SedonaType]) -> Result<Option<SedonaType>> {
+ let matcher = ArgMatcher::new(vec![ArgMatcher::is_geometry()], WKB_GEOMETRY);
+ matcher.match_args(args)
+ }
+
+ fn accumulator(
+ &self,
+ args: &[SedonaType],
+ _output_type: &SedonaType,
+ ) -> Result<Box<dyn Accumulator>> {
+ Ok(Box::new(UnionAccumulator::new(args[0].clone())))
+ }
+
+ fn state_fields(&self, _args: &[SedonaType]) -> Result<Vec<FieldRef>> {
+ Ok(vec![
+ Arc::new(Field::new("types_and_dims", DataType::UInt32, false)),
+ Arc::new(Field::new("empty_types", DataType::UInt32, false)),
+ Arc::new(Field::new("count", DataType::UInt64, false)),
+ Arc::new(Field::new("item", DataType::Binary, true)),
+ ])
+ }
+}
+
+#[derive(Debug)]
+struct UnionAccumulator {
+ input_type: SedonaType,
+ types_and_dims: GeometryTypeAndDimensionsSet,
+ empty_types: GeometryTypeAndDimensionsSet,
+ item: Vec<u8>,
+ count: usize,
+}
+
+const WKB_HEADER_SIZE: usize = 1 + 4 + 4;
+
+fn empty_collection() -> Vec<u8> {
+ let mut item = Vec::new();
+ write_wkb_geometrycollection_header(&mut item, Dimensions::Xy, 0)
+ .expect("Failed to write initial GeometryCollection header");
+ item
+}
+
+impl UnionAccumulator {
+ fn new(input_type: SedonaType) -> Self {
+ Self {
+ input_type,
+ types_and_dims: GeometryTypeAndDimensionsSet::new(),
+ empty_types: GeometryTypeAndDimensionsSet::new(),
+ item: empty_collection(),
+ count: 0,
+ }
+ }
+
+ fn make_wkb_result(&mut self) -> Result<Option<Vec<u8>>> {
+ if self.count == 0 {
+ return self.make_empty_result();
+ }
+
+ let unique_dimensions = self.types_and_dims.dimensions();
+ if unique_dimensions.len() != 1 {
+ return exec_err!("Can't ST_Union_Agg() mixed dimension geometries");
+ }
+
+ let mut header = Vec::new();
+ write_wkb_geometrycollection_header(&mut header, unique_dimensions[0], self.count)
+ .map_err(|e| DataFusionError::Execution(format!("Failed to write header: {e}")))?;
+ self.item[0..WKB_HEADER_SIZE].copy_from_slice(&header);
+
+ let wkb = read_wkb(&self.item)
+ .map_err(|e| DataFusionError::Execution(format!("Failed to read WKB: {e}")))?;
+ let collection = GEOSWkbFactory::new().create(&wkb).map_err(|e| {
+ DataFusionError::Execution(format!("Failed to create geometry from WKB: {e}"))
+ })?;
+ let union = collection
+ .unary_union()
+ .map_err(|e| DataFusionError::Execution(format!("Failed to compute union: {e}")))?;
+ let mut wkb = Vec::new();
+ write_geos_geometry(&union, &mut wkb)?;
+
+ Ok(Some(wkb))
+ }
+
+ fn make_empty_result(&self) -> Result<Option<Vec<u8>>> {
+ let Some(geometry_type) = self
+ .empty_types
+ .geometry_types()
+ .into_iter()
+ .max_by_key(|geometry_type| geometry_type.wkb_id())
+ else {
+ return Ok(None);
+ };
+
+ let mut wkb = Vec::new();
+ let dims = Dimensions::Xy;
+ match geometry_type {
+ GeometryTypeId::Point => write_wkb_empty_point(&mut wkb, dims),
+ GeometryTypeId::LineString => write_wkb_linestring_header(&mut wkb, dims, 0),
+ GeometryTypeId::Polygon => write_wkb_polygon_header(&mut wkb, dims, 0),
+ GeometryTypeId::MultiPoint => write_wkb_multipoint_header(&mut wkb, dims, 0),
+ GeometryTypeId::MultiLineString => write_wkb_multilinestring_header(&mut wkb, dims, 0),
+ GeometryTypeId::MultiPolygon => write_wkb_multipolygon_header(&mut wkb, dims, 0),
+ GeometryTypeId::GeometryCollection | GeometryTypeId::Geometry => {
+ write_wkb_geometrycollection_header(&mut wkb, dims, 0)
+ }
+ }
+ .map_err(|e| DataFusionError::External(Box::new(e)))?;
+
+ Ok(Some(wkb))
+ }
+}
+
+impl Accumulator for UnionAccumulator {
+ fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
+ if values.is_empty() {
+ return sedona_internal_err!("No input arrays provided to accumulator in update_batch");
+ }
+
+ let arg_types = std::slice::from_ref(&self.input_type);
+ let args = [ColumnarValue::Array(values[0].clone())];
+ let executor = sedona_functions::executor::WkbExecutor::new(arg_types, &args);
+
+ executor.execute_wkb_void(|maybe_item| {
+ if let Some(item) = maybe_item {
+ let types_and_dims = GeometryTypeAndDimensions::try_from_geom(&item)
+ .map_err(|e| DataFusionError::External(Box::new(e)))?;
+ if is_geometry_empty(&item).map_err(|e| DataFusionError::External(Box::new(e)))? {
Review Comment:
Done in this PR, it was a small change. Emptiness is checked recursively now (collections and multi geometries whose members are all EMPTY count as EMPTY), so your query returns POINT (1 2) like PostGIS, and GEOMETRYCOLLECTION Z (POINT Z EMPTY) on its own gives GEOMETRYCOLLECTION EMPTY. Added both plus a nested GEOMETRYCOLLECTION case to the Rust and Python tests.
--
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: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(c/sedona-geos): implement ST_Union_Agg with GEOS [sedona-db]
Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot commented on code in PR #1468:
URL: https://github.com/apache/sedona-db/pull/1468#discussion_r4414802315
##########
c/sedona-geos/src/st_union_agg.rs:
##########
@@ -0,0 +1,515 @@
+// 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 std::sync::Arc;
+
+use crate::{geos_to_wkb::write_geos_geometry, wkb_to_geos::GEOSWkbFactory};
+use arrow_array::{
+ cast::AsArray,
+ types::{UInt32Type, UInt64Type},
+ Array, ArrayRef,
+};
+use arrow_schema::{DataType, Field, FieldRef};
+use datafusion_common::{
+ cast::as_binary_array, error::Result, exec_err, DataFusionError, ScalarValue,
+};
+use datafusion_expr::{Accumulator, ColumnarValue};
+use geo_traits::{
+ Dimensions, GeometryCollectionTrait, GeometryTrait, GeometryType, LineStringTrait,
+ MultiLineStringTrait, MultiPointTrait, MultiPolygonTrait, PointTrait, PolygonTrait,
+};
+use geos::Geom;
+use sedona_common::sedona_internal_err;
+use sedona_expr::{
+ aggregate_udf::{SedonaAccumulator, SedonaAccumulatorRef},
+ item_crs::ItemCrsSedonaAccumulator,
+};
+use sedona_geometry::{
+ types::{GeometryTypeAndDimensions, GeometryTypeAndDimensionsSet, GeometryTypeId},
+ wkb_factory::{
+ write_wkb_empty_point, write_wkb_geometrycollection_header, write_wkb_linestring_header,
+ write_wkb_multilinestring_header, write_wkb_multipoint_header,
+ write_wkb_multipolygon_header, write_wkb_polygon_header,
+ },
+};
+use sedona_schema::{
+ datatypes::{SedonaType, WKB_GEOMETRY},
+ matchers::ArgMatcher,
+};
+use wkb::reader::read_wkb;
+
+/// ST_Union_Agg() aggregate implementation using GEOS
+pub fn st_union_agg_impl() -> Vec<SedonaAccumulatorRef> {
+ ItemCrsSedonaAccumulator::wrap_impl(STUnionAgg {})
+}
+
+#[derive(Debug)]
+struct STUnionAgg {}
+
+impl SedonaAccumulator for STUnionAgg {
+ fn return_type(&self, args: &[SedonaType]) -> Result<Option<SedonaType>> {
+ let matcher = ArgMatcher::new(vec![ArgMatcher::is_geometry()], WKB_GEOMETRY);
+ matcher.match_args(args)
+ }
+
+ fn accumulator(
+ &self,
+ args: &[SedonaType],
+ _output_type: &SedonaType,
+ ) -> Result<Box<dyn Accumulator>> {
+ Ok(Box::new(UnionAccumulator::new(args[0].clone())))
+ }
+
+ fn state_fields(&self, _args: &[SedonaType]) -> Result<Vec<FieldRef>> {
+ Ok(vec![
+ Arc::new(Field::new("types_and_dims", DataType::UInt32, false)),
+ Arc::new(Field::new("empty_types", DataType::UInt32, false)),
+ Arc::new(Field::new("count", DataType::UInt64, false)),
+ Arc::new(Field::new("item", DataType::Binary, true)),
+ ])
+ }
+}
+
+#[derive(Debug)]
+struct UnionAccumulator {
+ input_type: SedonaType,
+ types_and_dims: GeometryTypeAndDimensionsSet,
+ empty_types: GeometryTypeAndDimensionsSet,
+ item: Vec<u8>,
+ count: usize,
+}
+
+const WKB_HEADER_SIZE: usize = 1 + 4 + 4;
+
+fn is_empty_recursive(geometry: &impl GeometryTrait<T = f64>) -> bool {
+ match geometry.as_type() {
+ GeometryType::Point(point) => point.coord().is_none(),
+ GeometryType::LineString(line_string) => line_string.num_coords() == 0,
+ GeometryType::Polygon(polygon) => is_polygon_empty(polygon),
+ GeometryType::MultiPoint(multi_point) => {
+ multi_point.points().all(|point| point.coord().is_none())
+ }
+ GeometryType::MultiLineString(multi_line_string) => multi_line_string
+ .line_strings()
+ .all(|line_string| line_string.num_coords() == 0),
+ GeometryType::MultiPolygon(multi_polygon) => multi_polygon
+ .polygons()
+ .all(|polygon| is_polygon_empty(&polygon)),
+ GeometryType::GeometryCollection(collection) => collection
+ .geometries()
+ .all(|member| is_empty_recursive(&member)),
+ _ => false,
+ }
+}
+
+fn is_polygon_empty(polygon: &impl PolygonTrait<T = f64>) -> bool {
+ polygon.num_interiors() == 0
+ && polygon
+ .exterior()
+ .is_none_or(|exterior| exterior.num_coords() == 0)
+}
+
+fn empty_collection() -> Vec<u8> {
+ let mut item = Vec::new();
+ write_wkb_geometrycollection_header(&mut item, Dimensions::Xy, 0)
+ .expect("Failed to write initial GeometryCollection header");
+ item
+}
+
+impl UnionAccumulator {
+ fn new(input_type: SedonaType) -> Self {
+ Self {
+ input_type,
+ types_and_dims: GeometryTypeAndDimensionsSet::new(),
+ empty_types: GeometryTypeAndDimensionsSet::new(),
+ item: empty_collection(),
+ count: 0,
+ }
+ }
+
+ fn make_wkb_result(&mut self) -> Result<Option<Vec<u8>>> {
+ if self.count == 0 {
+ return self.make_empty_result();
+ }
+
+ let unique_dimensions = self.types_and_dims.dimensions();
+ if unique_dimensions.len() != 1 {
+ return exec_err!("Can't ST_Union_Agg() mixed dimension geometries");
+ }
+
+ let mut header = Vec::new();
+ write_wkb_geometrycollection_header(&mut header, unique_dimensions[0], self.count)
+ .map_err(|e| DataFusionError::Execution(format!("Failed to write header: {e}")))?;
+ self.item[0..WKB_HEADER_SIZE].copy_from_slice(&header);
+
+ let wkb = read_wkb(&self.item)
+ .map_err(|e| DataFusionError::Execution(format!("Failed to read WKB: {e}")))?;
+ let collection = GEOSWkbFactory::new().create(&wkb).map_err(|e| {
+ DataFusionError::Execution(format!("Failed to create geometry from WKB: {e}"))
+ })?;
+ let union = collection
+ .unary_union()
Review Comment:
I think this is follow-up material...being able to handle all geometry types is a feature we need to stay on parity with all the other engines that implement this. There are a few things we can do to improve the performance and memory efficiency...I filed https://github.com/apache/sedona-db/issues/1536 to track.
--
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: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(c/sedona-geos): implement ST_Union_Agg with GEOS [sedona-db]
Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot merged PR #1468:
URL: https://github.com/apache/sedona-db/pull/1468
--
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: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(c/sedona-geos): implement ST_Union_Agg with GEOS [sedona-db]
Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu commented on code in PR #1468:
URL: https://github.com/apache/sedona-db/pull/1468#discussion_r4385347301
##########
c/sedona-geos/src/st_union_agg.rs:
##########
@@ -0,0 +1,467 @@
+// 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 std::sync::Arc;
+
+use crate::{geos_to_wkb::write_geos_geometry, wkb_to_geos::GEOSWkbFactory};
+use arrow_array::{
+ cast::AsArray,
+ types::{UInt32Type, UInt64Type},
+ Array, ArrayRef,
+};
+use arrow_schema::{DataType, Field, FieldRef};
+use datafusion_common::{
+ cast::as_binary_array, error::Result, exec_err, DataFusionError, ScalarValue,
+};
+use datafusion_expr::{Accumulator, ColumnarValue};
+use geo_traits::Dimensions;
+use geos::Geom;
+use sedona_common::sedona_internal_err;
+use sedona_expr::{
+ aggregate_udf::{SedonaAccumulator, SedonaAccumulatorRef},
+ item_crs::ItemCrsSedonaAccumulator,
+};
+use sedona_geometry::{
+ is_empty::is_geometry_empty,
+ types::{GeometryTypeAndDimensions, GeometryTypeAndDimensionsSet, GeometryTypeId},
+ wkb_factory::{
+ write_wkb_empty_point, write_wkb_geometrycollection_header, write_wkb_linestring_header,
+ write_wkb_multilinestring_header, write_wkb_multipoint_header,
+ write_wkb_multipolygon_header, write_wkb_polygon_header,
+ },
+};
+use sedona_schema::{
+ datatypes::{SedonaType, WKB_GEOMETRY},
+ matchers::ArgMatcher,
+};
+use wkb::reader::read_wkb;
+
+/// ST_Union_Agg() aggregate implementation using GEOS
+pub fn st_union_agg_impl() -> Vec<SedonaAccumulatorRef> {
+ ItemCrsSedonaAccumulator::wrap_impl(STUnionAgg {})
+}
+
+#[derive(Debug)]
+struct STUnionAgg {}
+
+impl SedonaAccumulator for STUnionAgg {
+ fn return_type(&self, args: &[SedonaType]) -> Result<Option<SedonaType>> {
+ let matcher = ArgMatcher::new(vec![ArgMatcher::is_geometry()], WKB_GEOMETRY);
+ matcher.match_args(args)
+ }
+
+ fn accumulator(
+ &self,
+ args: &[SedonaType],
+ _output_type: &SedonaType,
+ ) -> Result<Box<dyn Accumulator>> {
+ Ok(Box::new(UnionAccumulator::new(args[0].clone())))
+ }
+
+ fn state_fields(&self, _args: &[SedonaType]) -> Result<Vec<FieldRef>> {
+ Ok(vec![
+ Arc::new(Field::new("types_and_dims", DataType::UInt32, false)),
+ Arc::new(Field::new("empty_types", DataType::UInt32, false)),
+ Arc::new(Field::new("count", DataType::UInt64, false)),
+ Arc::new(Field::new("item", DataType::Binary, true)),
+ ])
+ }
+}
+
+#[derive(Debug)]
+struct UnionAccumulator {
+ input_type: SedonaType,
+ types_and_dims: GeometryTypeAndDimensionsSet,
+ empty_types: GeometryTypeAndDimensionsSet,
+ item: Vec<u8>,
+ count: usize,
+}
+
+const WKB_HEADER_SIZE: usize = 1 + 4 + 4;
+
+fn empty_collection() -> Vec<u8> {
+ let mut item = Vec::new();
+ write_wkb_geometrycollection_header(&mut item, Dimensions::Xy, 0)
+ .expect("Failed to write initial GeometryCollection header");
+ item
+}
+
+impl UnionAccumulator {
+ fn new(input_type: SedonaType) -> Self {
+ Self {
+ input_type,
+ types_and_dims: GeometryTypeAndDimensionsSet::new(),
+ empty_types: GeometryTypeAndDimensionsSet::new(),
+ item: empty_collection(),
+ count: 0,
+ }
+ }
+
+ fn make_wkb_result(&mut self) -> Result<Option<Vec<u8>>> {
+ if self.count == 0 {
+ return self.make_empty_result();
+ }
+
+ let unique_dimensions = self.types_and_dims.dimensions();
+ if unique_dimensions.len() != 1 {
+ return exec_err!("Can't ST_Union_Agg() mixed dimension geometries");
+ }
+
+ let mut header = Vec::new();
+ write_wkb_geometrycollection_header(&mut header, unique_dimensions[0], self.count)
+ .map_err(|e| DataFusionError::Execution(format!("Failed to write header: {e}")))?;
+ self.item[0..WKB_HEADER_SIZE].copy_from_slice(&header);
+
+ let wkb = read_wkb(&self.item)
+ .map_err(|e| DataFusionError::Execution(format!("Failed to read WKB: {e}")))?;
+ let collection = GEOSWkbFactory::new().create(&wkb).map_err(|e| {
+ DataFusionError::Execution(format!("Failed to create geometry from WKB: {e}"))
+ })?;
+ let union = collection
+ .unary_union()
+ .map_err(|e| DataFusionError::Execution(format!("Failed to compute union: {e}")))?;
+ let mut wkb = Vec::new();
+ write_geos_geometry(&union, &mut wkb)?;
+
+ Ok(Some(wkb))
+ }
+
+ fn make_empty_result(&self) -> Result<Option<Vec<u8>>> {
+ let Some(geometry_type) = self
+ .empty_types
+ .geometry_types()
+ .into_iter()
+ .max_by_key(|geometry_type| geometry_type.wkb_id())
+ else {
+ return Ok(None);
+ };
+
+ let mut wkb = Vec::new();
+ let dims = Dimensions::Xy;
+ match geometry_type {
+ GeometryTypeId::Point => write_wkb_empty_point(&mut wkb, dims),
+ GeometryTypeId::LineString => write_wkb_linestring_header(&mut wkb, dims, 0),
+ GeometryTypeId::Polygon => write_wkb_polygon_header(&mut wkb, dims, 0),
+ GeometryTypeId::MultiPoint => write_wkb_multipoint_header(&mut wkb, dims, 0),
+ GeometryTypeId::MultiLineString => write_wkb_multilinestring_header(&mut wkb, dims, 0),
+ GeometryTypeId::MultiPolygon => write_wkb_multipolygon_header(&mut wkb, dims, 0),
+ GeometryTypeId::GeometryCollection | GeometryTypeId::Geometry => {
+ write_wkb_geometrycollection_header(&mut wkb, dims, 0)
+ }
+ }
+ .map_err(|e| DataFusionError::External(Box::new(e)))?;
+
+ Ok(Some(wkb))
+ }
+}
+
+impl Accumulator for UnionAccumulator {
+ fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
+ if values.is_empty() {
+ return sedona_internal_err!("No input arrays provided to accumulator in update_batch");
+ }
+
+ let arg_types = std::slice::from_ref(&self.input_type);
+ let args = [ColumnarValue::Array(values[0].clone())];
+ let executor = sedona_functions::executor::WkbExecutor::new(arg_types, &args);
+
+ executor.execute_wkb_void(|maybe_item| {
+ if let Some(item) = maybe_item {
+ let types_and_dims = GeometryTypeAndDimensions::try_from_geom(&item)
+ .map_err(|e| DataFusionError::External(Box::new(e)))?;
+ if is_geometry_empty(&item).map_err(|e| DataFusionError::External(Box::new(e)))? {
Review Comment:
Nonblocking: could we also handle collections whose members are all empty?
```sql
SELECT ST_AsText(ST_Union_Agg(ST_GeomFromText(geom)))
FROM (VALUES
('GEOMETRYCOLLECTION Z (POINT Z EMPTY)'),
('POINT (1 2)')
) AS t(geom);
```
I get `Can't ST_Union_Agg() mixed dimension geometries` on this head; PostGIS returns `POINT(1 2)`. Replacing the collection with `POINT Z EMPTY` works here too.
This helper only checks whether a collection has any members, so the empty child still gets counted in the dimension check. Could we check the members recursively? This seems uncommon, so a follow-up is fine with me.
--
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: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org