paleolimbot commented on code in PR #255:
URL: https://github.com/apache/sedona-db/pull/255#discussion_r2473651318


##########
rust/sedona-functions/src/st_pointn.rs:
##########
@@ -0,0 +1,286 @@
+// 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 arrow_array::builder::BinaryBuilder;
+use arrow_schema::DataType;
+use datafusion_common::{error::Result, ScalarValue};
+use datafusion_expr::{
+    scalar_doc_sections::DOC_SECTION_OTHER, ColumnarValue, Documentation, 
Volatility,
+};
+use geo_traits::{CoordTrait, GeometryTrait, LineStringTrait};
+use sedona_common::sedona_internal_err;
+use sedona_expr::scalar_udf::{SedonaScalarKernel, SedonaScalarUDF};
+use sedona_geometry::{
+    error::SedonaGeometryError,
+    wkb_factory::{write_wkb_coord_trait, write_wkb_point_header, 
WKB_MIN_PROBABLE_BYTES},
+};
+use sedona_schema::{
+    datatypes::{SedonaType, WKB_GEOMETRY},
+    matchers::ArgMatcher,
+};
+use std::{io::Write, sync::Arc};
+
+use crate::executor::WkbExecutor;
+
+/// ST_PointN() scalar UDF
+///
+/// Native implementation to get the nth point of a LINESTRING geometry.
+pub fn st_pointn_udf() -> SedonaScalarUDF {
+    SedonaScalarUDF::new(
+        "st_pointn",
+        vec![Arc::new(STPointN::new())],
+        Volatility::Immutable,
+        Some(st_pointn_doc()),
+    )
+}
+
+fn st_pointn_doc() -> Documentation {
+    Documentation::builder(
+        DOC_SECTION_OTHER,
+        "Returns the nth point of a geometry. Returns NULL if the geometry is 
empty or not a LINESTRING. Negative values are counted backwards from the end.",
+        "ST_PointN (geom: Geometry, n: integer)",
+    )
+    .with_argument("geom", "geometry: Input geometry")
+    .with_argument("n", "n: Index")
+    .with_sql_example("SELECT ST_PointN(ST_GeomFromWKT('LINESTRING(0 1, 2 3, 4 
5)'), 2)")
+    .build()
+}
+
+#[derive(Debug)]
+struct STPointN;
+
+impl STPointN {
+    fn new() -> Self {
+        Self
+    }
+}

Review Comment:
   ```suggestion
   impl STPointN {}
   ```
   
   (For all the other kernels we skip the `new()` since they are only 
constructed in one place)



##########
rust/sedona-schema/src/matchers.rs:
##########
@@ -356,6 +366,38 @@ impl TypeMatcher for IsNumeric {
     }
 }
 
+#[derive(Debug)]
+struct IsInteger {}
+
+impl TypeMatcher for IsInteger {
+    fn match_type(&self, arg: &SedonaType) -> bool {
+        match arg {
+            SedonaType::Arrow(data_type) => data_type.is_integer(),
+            _ => false,
+        }
+    }
+
+    fn type_if_null(&self) -> Option<SedonaType> {
+        Some(SedonaType::Arrow(DataType::Float64))

Review Comment:
   ```suggestion
           Some(SedonaType::Arrow(DataType::Int64))
   ```



##########
rust/sedona-schema/src/matchers.rs:
##########
@@ -356,6 +366,38 @@ impl TypeMatcher for IsNumeric {
     }
 }
 
+#[derive(Debug)]
+struct IsInteger {}
+
+impl TypeMatcher for IsInteger {
+    fn match_type(&self, arg: &SedonaType) -> bool {
+        match arg {
+            SedonaType::Arrow(data_type) => data_type.is_integer(),
+            _ => false,
+        }
+    }
+
+    fn type_if_null(&self) -> Option<SedonaType> {
+        Some(SedonaType::Arrow(DataType::Float64))
+    }
+}
+
+#[derive(Debug)]
+struct IsUnsignedInteger {}
+
+impl TypeMatcher for IsUnsignedInteger {
+    fn match_type(&self, arg: &SedonaType) -> bool {
+        match arg {
+            SedonaType::Arrow(data_type) => data_type.is_unsigned_integer(),
+            _ => false,
+        }
+    }
+
+    fn type_if_null(&self) -> Option<SedonaType> {
+        Some(SedonaType::Arrow(DataType::Float64))

Review Comment:
   ```suggestion
           Some(SedonaType::Arrow(DataType::UInt64))
   ```
   
   Do we need specifically unsigned integers for anything at the type matching 
level? It would probably be a better error coming from a kernel like 
"some_parameter must be greater than zero" than a planning error like "no 
kernel matching args ...".



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