petern48 commented on code in PR #387: URL: https://github.com/apache/sedona-db/pull/387#discussion_r2581738385
########## c/sedona-geos/src/st_nrings.rs: ########## @@ -0,0 +1,177 @@ +// 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, GeometryTypes}; // Removed unused 'Geometry' +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) => { + // Fixed: Removed the unused 'res' variable assignment + // and directly appended the result. Review Comment: Just as an FYI @LakshmiSowmya04, usually when I suggest removing comments like these. It means it's one I think we *should* remove. But it also generally means that other comments that I don't suggest on are *fine* to leave in. I'm just pointing this out since I've noticed you often delete more than I ask (e.g. in here https://github.com/apache/sedona-db/pull/387/commits/02ddb50e17a9c0b2b3b04974632faa064caba0a1). Deleting more is totally okay (I probably would delete some of these as well), but I just wanted to let you know it's generally fine to leave other comments in, if you prefer to / think they're helpful. ########## python/sedonadb/tests/functions/test_functions.py: ########## @@ -2889,3 +2889,49 @@ def test_st_numpoints(eng, geom, expected): f"SELECT ST_NumPoints({geom_or_null(geom)})", expected, ) + + [email protected]("eng", [SedonaDB, PostGIS]) [email protected]( + ("geom", "expected"), + [ + (None, None), + ("POINT (1 2)", 0), + ("LINESTRING (0 0, 1 1, 2 2)", 0), + ("MULTIPOINT ((0 0), (1 1))", 0), + ("MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))", 0), + ("POINT EMPTY", 0), + ("MULTIPOINT EMPTY", 0), + ("LINESTRING EMPTY", 0), + ("MULTILINESTRING EMPTY", 0), + ("MULTIPOINT ((0 0), (1 1))", 0), + ("MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))", 0), + ("POINT EMPTY", 0), + ("MULTIPOINT EMPTY", 0), + ("LINESTRING EMPTY", 0), + ("MULTILINESTRING EMPTY", 0), Review Comment: ```suggestion ("POLYGON EMPTY", 0), ("MULTIPOLYGON EMPTY", 0), ``` Let's undo that [last commit](https://github.com/apache/sedona-db/pull/387/commits/51297de7dee41dfa8fccf988f55560c2890403cb). Looks like it removed these empty polygon tests and replaced it with duplicate versions of existing tests that are still there. -- 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]
