jesspav commented on code in PR #38:
URL: https://github.com/apache/sedona-db/pull/38#discussion_r2337384191


##########
rust/sedona-functions/src/st_srid.rs:
##########
@@ -94,6 +118,52 @@ impl SedonaScalarKernel for StSrid {
     }
 }
 
+#[derive(Debug)]
+struct StCrs {}
+
+impl SedonaScalarKernel for StCrs {
+    fn return_type(&self, args: &[SedonaType]) -> Result<Option<SedonaType>> {
+        let matcher = ArgMatcher::new(
+            vec![ArgMatcher::is_geometry_or_geography()],
+            SedonaType::Arrow(DataType::Utf8),
+        );
+
+        matcher.match_args(args)
+    }
+
+    fn invoke_batch(
+        &self,
+        arg_types: &[SedonaType],
+        args: &[ColumnarValue],
+    ) -> Result<ColumnarValue> {
+        let executor = WkbExecutor::new(arg_types, args);
+        let preallocate_bytes = "EPSG:4326".len() * executor.num_iterations();
+        let mut builder =
+            StringBuilder::with_capacity(executor.num_iterations(), 
preallocate_bytes);
+        let crs_opt: Option<String> = match &arg_types[0] {
+            SedonaType::Wkb(_, Some(crs)) | SedonaType::WkbView(_, Some(crs)) 
=> {
+                match crs.to_authority_code()? {
+                    Some(auth_code) => Some(auth_code),
+                    None => Some(crs.to_json()),
+                }
+            }
+            _ => None,
+        };
+
+        executor.execute_wkb_void(|maybe_wkb| {
+            match maybe_wkb {
+                Some(_wkb) => builder.append_option(crs_opt.clone()),
+
+                _ => builder.append_null(),
+            }
+
+            Ok(())
+        })?;

Review Comment:
   Discussed offline with @paleolimbot .  We agreed that there is a deeper 
issue that blocks us from being able to do  `ST_SetCRS(geom, 
ST_CRS(other_geom))`, since the CRS is currently embedded in the type so we 
need to know the CRS at the planning stage in order to create the correct 
return type.   Fixing that is out of scope for this review.



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