2010YOUY01 commented on code in PR #90: URL: https://github.com/apache/sedona-db/pull/90#discussion_r2355987772
########## rust/sedona-functions/src/executor.rs: ########## @@ -246,6 +246,58 @@ impl GeometryFactory for WkbGeometryFactory { } } +#[derive(Default)] +pub(crate) struct WkbBytesFactory {} + +impl GeometryFactory for WkbBytesFactory { + type Geom<'a> = &'a [u8]; + + fn try_from_wkb<'a>(&self, wkb_bytes: &'a [u8]) -> Result<Self::Geom<'a>> { + Ok(wkb_bytes) + } +} + +/// Alias for an executor that iterates over geometries in their raw [Wkb] bytes. +/// +/// This [GenericExecutor] implementation provides more optimization opportunities, +/// but it requires additional manual processing of the raw [Wkb] bytes compared to +/// the [WkbExecutor]. +pub(crate) type WkbBytesExecutor<'a, 'b> = + GenericExecutor<'a, 'b, WkbBytesFactory, WkbBytesFactory>; + +impl<'b> GenericExecutor<'_, 'b, WkbBytesFactory, WkbBytesFactory> { + /// Execute a function by iterating over [Wkb]'s raw binary representation. + /// The provided `func` can assume its input bytes is a valid [Wkb] binary. + pub fn execute_wkb_bytes_void<F: FnMut(Option<&'b [u8]>) -> Result<()>>( + &self, + mut func: F, + ) -> Result<()> { + // Ensure the first argument of the executor is either Wkb, WkbView, or + // a Null type (to support columns of all-null values) + match &self.arg_types[0] { + SedonaType::Wkb(_, _) + | SedonaType::WkbView(_, _) + | SedonaType::Arrow(DataType::Null) => {} + other => { + return sedona_internal_err!( + "Expected SedonaType::Wkb or SedonaType::WkbView or SedonaType::Arrow(DataType::Null) for the first arg, got {}", + other + ) + } + } + + match &self.args[0] { + ColumnarValue::Array(array) => { + array.iter_as_wkb_bytes(&self.arg_types[0], self.num_iterations, func) + } + ColumnarValue::Scalar(scalar_value) => { + let maybe_bytes = scalar_value.scalar_as_wkb_bytes()?; + func(maybe_bytes) + } + } + } +} + Review Comment: You're right. Updated in [df88be5](https://github.com/apache/sedona-db/pull/90/commits/df88be5f08779b27da527633d3e54969bc859716) -- 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: issues-unsubscr...@sedona.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org