Copilot commented on code in PR #31:
URL: https://github.com/apache/sedona-db/pull/31#discussion_r2325734107


##########
rust/sedona-schema/src/crs.rs:
##########
@@ -207,6 +208,11 @@ impl CoordinateReferenceSystem for AuthorityCode {
             (_, _) => false,
         }
     }
+
+    /// Get the SRID if the authority is EPSG
+    fn srid(&self) -> Option<u32> {
+        self.code.parse::<u32>().ok()

Review Comment:
   The SRID implementation for AuthorityCode ignores the authority and always 
tries to parse the code as u32. This will return incorrect results for non-EPSG 
authorities. The method should check if the authority is 'EPSG' before parsing 
the code.
   ```suggestion
           if self.authority.eq_ignore_ascii_case("EPSG") {
               self.code.parse::<u32>().ok()
           } else {
               None
           }
   ```



##########
rust/sedona-functions/src/st_srid.rs:
##########
@@ -0,0 +1,153 @@
+// 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::UInt32Builder;
+use std::{sync::Arc, vec};
+
+use crate::executor::WkbExecutor;
+use arrow_schema::DataType;
+use datafusion_common::{DataFusionError, Result};
+use datafusion_expr::{
+    scalar_doc_sections::DOC_SECTION_OTHER, ColumnarValue, Documentation, 
Volatility,
+};
+use sedona_expr::scalar_udf::{ArgMatcher, SedonaScalarKernel, SedonaScalarUDF};
+use sedona_schema::datatypes::SedonaType;
+
+/// ST_Srid() scalar UDF implementation
+///
+/// Scalar function to return the SRID of a geometry or geography
+pub fn st_srid_udf() -> SedonaScalarUDF {
+    SedonaScalarUDF::new(
+        "st_srid",
+        vec![Arc::new(StSrid {})],
+        Volatility::Immutable,
+        Some(st_srid_doc()),
+    )
+}
+
+fn st_srid_doc() -> Documentation {
+    Documentation::builder(
+        DOC_SECTION_OTHER,
+        "Return the spatial reference system identifier (SRID) of the 
geometry.",
+        "ST_SRID (geom: Geometry)",
+    )
+    .with_argument("geom", "geometry: Input geometry or geography")
+    .with_sql_example("SELECT ST_SRID(polygon))".to_string())

Review Comment:
   Missing opening parenthesis in the SQL example. Should be 'SELECT 
ST_SRID(polygon)'.
   ```suggestion
       .with_sql_example("SELECT ST_SRID(polygon)".to_string())
   ```



##########
rust/sedona-schema/src/crs.rs:
##########
@@ -272,13 +278,28 @@ impl CoordinateReferenceSystem for ProjJSON {
             false
         }
     }
+
+    fn srid(&self) -> Option<u32> {
+        let authority_code_opt = self.to_authority_code().unwrap();
+        if let Some(authority_code) = authority_code_opt {
+            if LngLat::is_authority_code_lnglat(&authority_code) {
+                return Some(4326);
+            }
+            if let Some((_, code)) = 
AuthorityCode::split_auth_code(&authority_code) {
+                return code.parse::<u32>().ok();
+            }
+        }
+
+        None

Review Comment:
   Using `unwrap()` can cause a panic if `to_authority_code()` returns an 
error. Should use proper error handling with `?` operator or match statement.
   ```suggestion
       fn srid(&self) -> Result<Option<u32>> {
           let authority_code_opt = self.to_authority_code()?;
           if let Some(authority_code) = authority_code_opt {
               if LngLat::is_authority_code_lnglat(&authority_code) {
                   return Ok(Some(4326));
               }
               if let Some((_, code)) = 
AuthorityCode::split_auth_code(&authority_code) {
                   return Ok(code.parse::<u32>().ok());
               }
           }
   
           Ok(None)
   ```



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