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


##########
rust/sedona-schema/src/crs.rs:
##########
@@ -170,43 +185,33 @@ impl LngLat {
 /// Implementation of an authority:code CoordinateReferenceSystem
 #[derive(Debug)]
 struct AuthorityCode {
-    authority: String,
-    code: String,
+    auth_code: String,
 }
 
 /// Implementation of an authority:code
 impl AuthorityCode {
     /// Create a Crs from an authority:code string
     /// Example: "EPSG:4269"
-    pub fn crs(auth_code: String) -> Crs {
-        let (authority, code) = Self::split_auth_code(&auth_code).unwrap();
-        Crs::Some(Arc::new(AuthorityCode { authority, code }))
+    pub fn crs(auth_code: &str) -> Crs {
+        let ac = if Self::validate_epsg_code(auth_code) {
+            format!("EPSG:{}", auth_code)
+        } else {
+            auth_code.to_string()
+        };
+        Some(Arc::new(AuthorityCode { auth_code: ac }))
     }
 
     /// Check if a Value is an authority:code string
     /// Note: this can be expanded to more types in the future
-    pub fn is_authority_code(value: &Value) -> bool {
-        if let Some(string_value) = value.as_str() {
-            match Self::split_auth_code(string_value) {
-                Some((authority, code)) => {
-                    return Self::validate_authority(&authority) && 
Self::validate_code(&code)
-                }
-                None => return false,
-            }
-        }
-
-        false
-    }
-
-    /// Split an authority:code string into its components
-    fn split_auth_code(auth_code: &str) -> Option<(String, String)> {
-        let parts: Vec<&str> = auth_code.split(':').collect();
-        if parts.len() == 2 {
-            Some((parts[0].to_string(), parts[1].to_string()))
-        } else if parts.len() == 1 && Self::validate_epsg_code(auth_code) {
-            Some(("EPSG".to_string(), auth_code.to_string()))
+    pub fn is_authority_code(auth_code: &str) -> bool {
+        // Expecting <authority>:<code> format
+        if let Some(colon_pos) = auth_code.find(':') {
+            let authority = auth_code[..colon_pos].to_string();
+            let code = auth_code[colon_pos + 1..].to_string();
+            Self::validate_authority(&authority) && Self::validate_code(&code)

Review Comment:
   These string allocations are unnecessary for validation. Since 
`validate_authority` and `validate_code` take `&str`, pass string slices 
directly: `&auth_code[..colon_pos]` and `&auth_code[colon_pos + 1..]`.
   ```suggestion
               let authority = &auth_code[..colon_pos];
               let code = &auth_code[colon_pos + 1..];
               Self::validate_authority(authority) && Self::validate_code(code)
   ```



##########
rust/sedona-schema/src/datatypes.rs:
##########
@@ -312,8 +312,14 @@ fn deserialize_edges_and_crs(value: &Option<String>) -> 
Result<(Edges, Crs)> {
             };
 
             let crs = match json_value.get("crs") {
-                Some(crs_value) => deserialize_crs(crs_value)?,
-                None => Crs::None,
+                Some(crs_value) => {
+                    if let Some(s) = crs_value.as_str() {
+                        deserialize_crs(s)?
+                    } else {
+                        deserialize_crs(&crs_value.to_string())?
+                    }
+                }
+                None => None,

Review Comment:
   This should return `Crs::None` instead of `None`. The function returns 
`Result<(Edges, Crs)>`, and `Crs` is a type alias for `Option<Arc<dyn 
CoordinateReferenceSystem + Send + Sync>>`, so this creates a nested Option. 
The original code correctly used `Crs::None`.
   ```suggestion
                   None => Crs::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