paleolimbot commented on code in PR #38:
URL: https://github.com/apache/sedona-db/pull/38#discussion_r2334001680
##########
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:
If we're going to return an array here, I think
`ScalarValue::Utf8(crs_opt).to_array(executor.num_iterations())` would work too
(and avoid parsing all the WKB in the array).
I'm not sure the internals support it very well, but returning a
`ScalarValue` even for arrays (when the crs is attached to the type) would
probably help with SQL like `ST_SetCRS(geom, ST_CRS(other_geom))`. This might
mean that you can't use the `ScalarUdfTester` (which might error for such
cases).
--
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]