You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@sedona.apache.org by "yutannihilation (via GitHub)" <gi...@apache.org> on 2025/10/29 09:48:20 UTC

[PR] feat(sql): Implement ST_PointN [sedona-db]

yutannihilation opened a new pull request, #255:
URL: https://github.com/apache/sedona-db/pull/255

   https://postgis.net/docs/manual-3.5/en/ST_PointN.html
   
   - [ ] Add Python tests
   - [ ] Add benchmark
   


-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(sql): Implement ST_PointN [sedona-db]

Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot merged PR #255:
URL: https://github.com/apache/sedona-db/pull/255


-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(sql): Implement ST_PointN [sedona-db]

Posted by "yutannihilation (via GitHub)" <gi...@apache.org>.
yutannihilation commented on PR #255:
URL: https://github.com/apache/sedona-db/pull/255#issuecomment-3465956734

   Thanks, agreed!


-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(sql): Implement ST_PointN [sedona-db]

Posted by "yutannihilation (via GitHub)" <gi...@apache.org>.
yutannihilation commented on code in PR #255:
URL: https://github.com/apache/sedona-db/pull/255#discussion_r2475833280


##########
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:
   Ah, thanks for catching!



##########
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:
   Yeah, I was wondering about it... Maybe I should remove this? We can add when we find this is actually useful.



-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(sql): Implement ST_PointN [sedona-db]

Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot commented on code in PR #255:
URL: https://github.com/apache/sedona-db/pull/255#discussion_r2476255960


##########
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::Int64))
+    }
+}
+
+#[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::UInt64))
+    }
+}
+

Review Comment:
   ```suggestion
   ```



##########
rust/sedona-schema/src/matchers.rs:
##########
@@ -455,6 +497,16 @@ mod tests {
             Some(SedonaType::Arrow(DataType::Float64))
         );
 
+        assert!(ArgMatcher::is_integer().match_type(&SedonaType::Arrow(DataType::UInt32)));
+        assert!(ArgMatcher::is_integer().match_type(&SedonaType::Arrow(DataType::Int32)));
+        assert!(!ArgMatcher::is_integer().match_type(&SedonaType::Arrow(DataType::Float64)));
+
+        assert!(ArgMatcher::is_unsigned_integer().match_type(&SedonaType::Arrow(DataType::UInt32)));
+        assert!(!ArgMatcher::is_unsigned_integer().match_type(&SedonaType::Arrow(DataType::Int32)));
+        assert!(
+            !ArgMatcher::is_unsigned_integer().match_type(&SedonaType::Arrow(DataType::Float64))
+        );
+

Review Comment:
   ```suggestion
   ```



-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(sql): Implement ST_PointN [sedona-db]

Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org