jesspav commented on code in PR #38:
URL: https://github.com/apache/sedona-db/pull/38#discussion_r2337448035
##########
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:
Outside of that, I 100% agree that parsing the binary is a waste, but I
thought we needed to return null if the geometry is null, so
`ScalarValue::Utf8(crs_opt).to_array(executor.num_iterations())` wouldn't quite
work, right?
--
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]