joonaspessi commented on code in PR #286:
URL: https://github.com/apache/sedona-db/pull/286#discussion_r2508024169


##########
c/sedona-geos/src/st_polygonize.rs:
##########
@@ -0,0 +1,311 @@
+// 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 arrow_array::{
+    builder::OffsetBufferBuilder, cast::as_list_array, Array, ArrayRef, 
BinaryArray,
+};
+use arrow_schema::{DataType, Field, FieldRef};
+use datafusion_common::{cast::as_binary_array, error::Result, DataFusionError, 
ScalarValue};
+use datafusion_expr::{Accumulator, ColumnarValue};
+use geos::Geom;
+use sedona_expr::aggregate_udf::{SedonaAccumulator, SedonaAccumulatorRef};
+use sedona_schema::{
+    datatypes::{SedonaType, WKB_GEOMETRY},
+    matchers::ArgMatcher,
+};
+
+/// ST_Polygonize() aggregate implementation using GEOS
+pub fn st_polygonize_impl() -> SedonaAccumulatorRef {
+    Arc::new(STPolygonize {})
+}
+
+#[derive(Debug)]
+struct STPolygonize {}
+
+impl SedonaAccumulator for STPolygonize {
+    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(PolygonizeAccumulator::new(args[0].clone())))
+    }
+
+    fn state_fields(&self, _args: &[SedonaType]) -> Result<Vec<FieldRef>> {
+        Ok(vec![Arc::new(Field::new(
+            "geometries",
+            DataType::List(Arc::new(Field::new("item", DataType::Binary, 
true))),
+            false,
+        ))])
+    }
+}
+
+#[derive(Debug)]
+struct PolygonizeAccumulator {
+    input_type: SedonaType,
+    geometries: Vec<Vec<u8>>,

Review Comment:
   Tried to think if this would work out. Using single buffer like in 
`ST_Collect`, would it require then to keep track of offsets and then re-slice 
the buffer so that we can pass them individually 
`geos::Geometry::polygonize(&[geom1, geom2, ...])`. If I got it right, it feels 
little complicated 



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