Brijesh-Thakkar commented on code in PR #19581:
URL: https://github.com/apache/datafusion/pull/19581#discussion_r2655468715
##########
datafusion/functions/src/string/octet_length.rs:
##########
@@ -90,7 +94,45 @@ impl ScalarUDFImpl for OctetLengthFunc {
let [array] = take_function_args(self.name(), &args.args)?;
match array {
- ColumnarValue::Array(v) =>
Ok(ColumnarValue::Array(length(v.as_ref())?)),
+ ColumnarValue::Array(v) => {
+ let arr: ArrayRef = v.clone();
+
+ if let Some(arr) = arr.as_any().downcast_ref::<StringArray>() {
+ let mut builder = Int32Builder::with_capacity(arr.len());
+ for i in 0..arr.len() {
+ if arr.is_null(i) {
+ builder.append_null();
+ } else {
+ builder.append_value(arr.value_length(i) as i32);
+ }
+ }
+ Ok(ColumnarValue::Array(Arc::new(builder.finish())))
Review Comment:
Keeping the index-based loop here intentionally.
value_length(i) reads directly from Arrow’s offsets buffer and avoids
constructing &str, which is more efficient and aligns with Arrow kernel
patterns.
Iterator-based len() would regress performance for octet_length.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]