This is an automated email from the ASF dual-hosted git repository.

paleolimbot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/sedona-db.git


The following commit(s) were added to refs/heads/main by this push:
     new b41442c1 feat(rust/sedona-functions): Add SRID to ST_GeomFromWKT (#449)
b41442c1 is described below

commit b41442c1a655dc534a25f86ac50827043f16688e
Author: Hiroaki Yutani <[email protected]>
AuthorDate: Mon Dec 15 11:37:51 2025 +0900

    feat(rust/sedona-functions): Add SRID to ST_GeomFromWKT (#449)
---
 python/sedonadb/tests/functions/test_functions.py | 21 ++++++++++
 rust/sedona-functions/src/st_geomfromwkt.rs       | 47 +++++++++++++++++++++--
 2 files changed, 64 insertions(+), 4 deletions(-)

diff --git a/python/sedonadb/tests/functions/test_functions.py 
b/python/sedonadb/tests/functions/test_functions.py
index da5aa9b3..609b255f 100644
--- a/python/sedonadb/tests/functions/test_functions.py
+++ b/python/sedonadb/tests/functions/test_functions.py
@@ -1146,6 +1146,27 @@ def test_st_geomfromtext(eng, wkt, expected):
     eng.assert_query_result(f"SELECT ST_GeomFromText({val_or_null(wkt)})", 
expected)
 
 
[email protected]("eng", [SedonaDB, PostGIS])
[email protected](
+    ("wkt", "srid", "expected"),
+    [
+        (None, None, None),
+        ("POINT (0 0)", None, None),
+        ("POINT (0 0)", 0, 0),
+        ("POINT (0 0)", 4326, 4326),
+        ("POINT (0 0)", "4326", 4326),
+    ],
+)
+def test_st_geomfromtext_with_srid(eng, wkt, srid, expected):
+    if wkt is not None:
+        wkt = f"'{wkt}'"
+    eng = eng.create_or_skip()
+    eng.assert_query_result(
+        f"SELECT ST_SRID(ST_GeomFromText({val_or_null(wkt)}, 
{val_or_null(srid)}))",
+        expected,
+    )
+
+
 @pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
 @pytest.mark.parametrize(
     ("geom"),
diff --git a/rust/sedona-functions/src/st_geomfromwkt.rs 
b/rust/sedona-functions/src/st_geomfromwkt.rs
index c50c9557..5c63c7e3 100644
--- a/rust/sedona-functions/src/st_geomfromwkt.rs
+++ b/rust/sedona-functions/src/st_geomfromwkt.rs
@@ -34,17 +34,21 @@ use wkb::Endianness;
 use wkt::Wkt;
 
 use crate::executor::WkbExecutor;
+use crate::st_setsrid::SRIDifiedKernel;
 
 /// ST_GeomFromWKT() UDF implementation
 ///
 /// An implementation of WKT reading using GeoRust's wkt crate.
 /// See [`st_geogfromwkt_udf`] for the corresponding geography function.
 pub fn st_geomfromwkt_udf() -> SedonaScalarUDF {
+    let kernel = Arc::new(STGeoFromWKT {
+        out_type: WKB_GEOMETRY,
+    });
+    let sridified_kernel = Arc::new(SRIDifiedKernel::new(kernel.clone()));
+
     let udf = SedonaScalarUDF::new(
         "st_geomfromwkt",
-        vec![Arc::new(STGeoFromWKT {
-            out_type: WKB_GEOMETRY,
-        })],
+        vec![sridified_kernel, kernel],
         Volatility::Immutable,
         Some(doc("ST_GeomFromWKT", "Geometry")),
     );
@@ -83,6 +87,7 @@ fn doc(name: &str, out_type_name: &str) -> Documentation {
             out_type_name.to_lowercase()
         ),
     )
+    .with_argument("srid", "srid: EPSG code to set (e.g., 4326)")
     .with_sql_example(format!("SELECT {name}('POINT(40.7128 -74.0060)')"))
     .with_related_udf("ST_AsText")
     .build()
@@ -146,8 +151,10 @@ fn invoke_scalar(wkt_bytes: &str, builder: &mut 
BinaryBuilder) -> Result<()> {
 mod tests {
     use arrow_schema::DataType;
     use datafusion_common::scalar::ScalarValue;
-    use datafusion_expr::ScalarUDF;
+    use datafusion_expr::{Literal, ScalarUDF};
     use rstest::rstest;
+    use sedona_schema::crs::lnglat;
+    use sedona_schema::datatypes::Edges;
     use sedona_testing::{
         compare::{assert_array_equal, assert_scalar_equal, 
assert_scalar_equal_wkb_geometry},
         create::{create_array, create_scalar},
@@ -194,6 +201,38 @@ mod tests {
         );
     }
 
+    #[rstest(
+        data_type => [DataType::Utf8, DataType::Utf8View],
+        srid => [
+            (DataType::UInt32, 4326),
+            (DataType::Int32, 4326),
+            (DataType::Utf8, "4326"),
+            (DataType::Utf8, "EPSG:4326"),
+        ]
+    )]
+    fn udf_with_srid(data_type: DataType, srid: (DataType, impl Literal + 
Copy)) {
+        let (srid_type, srid_value) = srid;
+
+        let udf = st_geomfromwkt_udf();
+        let tester = ScalarUdfTester::new(
+            udf.into(),
+            vec![SedonaType::Arrow(data_type), SedonaType::Arrow(srid_type)],
+        );
+
+        let return_type = tester
+            .return_type_with_scalar_scalar(Some("POINT (1 2)"), 
Some(srid_value))
+            .unwrap();
+        assert_eq!(return_type, SedonaType::Wkb(Edges::Planar, lnglat()));
+
+        // Scalar non-null
+        assert_scalar_equal_wkb_geometry(
+            &tester
+                .invoke_scalar_scalar("POINT (1 2)", srid_value)
+                .unwrap(),
+            Some("POINT (1 2)"),
+        );
+    }
+
     #[test]
     fn invalid_wkt() {
         let udf = st_geomfromwkt_udf();

Reply via email to