petern48 commented on code in PR #387:
URL: https://github.com/apache/sedona-db/pull/387#discussion_r2579555183


##########
c/sedona-geos/src/st_nrings.rs:
##########
@@ -0,0 +1,202 @@
+// 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::executor::GeosExecutor;
+use arrow_array::builder::Int32Builder;
+use arrow_schema::DataType;
+use datafusion_common::{error::Result, DataFusionError};
+use datafusion_expr::ColumnarValue;
+use geos::{Geom, Geometry, GeometryTypes};
+use sedona_expr::scalar_udf::{ScalarKernelRef, SedonaScalarKernel};
+use sedona_schema::{datatypes::SedonaType, matchers::ArgMatcher};
+
+pub fn st_nrings_impl() -> ScalarKernelRef {
+    Arc::new(STNRings {})
+}
+
+#[derive(Debug)]
+struct STNRings {}
+
+impl SedonaScalarKernel for STNRings {
+    fn return_type(&self, args: &[SedonaType]) -> Result<Option<SedonaType>> {
+        let matcher = ArgMatcher::new(
+            vec![ArgMatcher::is_geometry()],
+            SedonaType::Arrow(DataType::Int32),
+        );
+        matcher.match_args(args)
+    }
+
+    fn invoke_batch(
+        &self,
+        arg_types: &[SedonaType],
+        args: &[ColumnarValue],
+    ) -> Result<ColumnarValue> {
+        let executor = GeosExecutor::new(arg_types, args);
+        let mut builder = 
Int32Builder::with_capacity(executor.num_iterations());
+        executor.execute_wkb_void(|maybe_geom| {
+            match maybe_geom {
+                None => builder.append_null(),
+                Some(geom) => {
+                    let res = invoke_scalar(&geom)?;
+                    match res {
+                        Some(n) => builder.append_value(n),
+                        None => builder.append_null(),
+                    }

Review Comment:
   ```suggestion
                       builder.append_value(invoke_scalar(&geom)?;
   ```
   Looking at your code below, there aren't any cases that return `None`, so we 
should go ahead and avoid returning an Option here, so we don't have to handle 
`None`.
   
   In other words, you'll need to update `invoke_scalar` to return 
`Result<i32>` instead of `Result<Option<i32>>`. This will happen naturally if 
you follow the suggestion I made below about using the `count_rings_recursive` 
function instead.



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