petern48 commented on code in PR #691: URL: https://github.com/apache/sedona-db/pull/691#discussion_r2921822732
########## c/sedona-geos/src/st_relate.rs: ########## @@ -0,0 +1,78 @@ +// 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::StringBuilder; +use datafusion_common::error::Result; +use datafusion_common::DataFusionError; +use datafusion_expr::ColumnarValue; +use geos::Geom; +use sedona_expr::{ + item_crs::ItemCrsKernel, + scalar_udf::{ScalarKernelRef, SedonaScalarKernel}, +}; +use sedona_schema::{datatypes::SedonaType, matchers::ArgMatcher}; + +use crate::executor::GeosExecutor; + +/// ST_Relate implementation using GEOS +pub fn st_relate_impl() -> Vec<ScalarKernelRef> { + ItemCrsKernel::wrap_impl(STRelate {}) +} + +#[derive(Debug)] +struct STRelate {} + +impl SedonaScalarKernel for STRelate { + fn return_type(&self, args: &[SedonaType]) -> Result<Option<SedonaType>> { + let matcher = ArgMatcher::new( + vec![ArgMatcher::is_geometry(), ArgMatcher::is_geometry()], + SedonaType::Arrow(arrow_schema::DataType::Utf8), + ); + + matcher.match_args(args) + } + + fn invoke_batch( + &self, + arg_types: &[SedonaType], + args: &[ColumnarValue], + ) -> Result<ColumnarValue> { + let executor = GeosExecutor::new(arg_types, args); + + // ST_Relate returns a 9-char DE-9IM string per row; 9 bytes * n rows + let mut builder = + StringBuilder::with_capacity(executor.num_iterations(), 9 * executor.num_iterations()); + + executor.execute_wkb_wkb_void(|wkb1, wkb2| { + match (wkb1, wkb2) { + (Some(g1), Some(g2)) => { + let relate = g1 + .relate(g2) + .map_err(|e| DataFusionError::External(Box::new(e)))?; + + builder.append_value(relate); + } + _ => builder.append_null(), + } + Ok(()) + })?; + + executor.finish(Arc::new(builder.finish())) + } +} Review Comment: We are still missing rust and python tests. Both of these are *very* important to have before we merge. The example PR has examples of these as well. The rust tests should exist in this file, starting with: ```rust #[cfg(test)] mod tests { ``` The new python tests for st_relate should go in [test_predicates.py](https://github.com/apache/sedona-db/blob/20808454b5b3987658621240a00686de44142e27/python/sedonadb/tests/functions/test_predicates.py#L295) (since st_relate is a predicate). Make sure to read my comment (https://github.com/apache/sedona-db/pull/288#issuecomment-3507272685) about how to iterate on developing Python integration tests ########## .gitignore: ########## @@ -51,3 +51,4 @@ __pycache__ dev/release/.env /.luarc.json +.cargo/config.toml Review Comment: ```suggestion ``` ########## rust/sedona-testing/src/data.rs: ########## @@ -200,6 +200,7 @@ mod test { } #[test] + #[ignore = "requires downloading assets via submodules/download-assets.py"] Review Comment: ```suggestion ``` We shouldn't need this change. CI should download it so it should pass in CI. ########## rust/sedona-functions/src/register.rs: ########## @@ -105,6 +105,7 @@ pub fn default_function_set() -> FunctionSet { crate::st_xyzm::st_y_udf, crate::st_xyzm::st_z_udf, crate::st_zmflag::st_zmflag_udf, + crate::st_relate::st_relate_udf, Review Comment: nit: let's place this in alphabetical order too -- 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]
