Brijesh-Thakkar commented on code in PR #19581:
URL: https://github.com/apache/datafusion/pull/19581#discussion_r2655469769
##########
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())))
+ } else if let Some(arr) =
arr.as_any().downcast_ref::<LargeStringArray>()
+ {
+ let mut builder = Int64Builder::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 i64);
+ }
+ }
+ Ok(ColumnarValue::Array(Arc::new(builder.finish())))
Review Comment:
Keeping the index-based loop intentionally.
value_length(i) reads directly from the Arrow offsets buffer and avoids
constructing &str, which is more efficient and appropriate 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]