andygrove commented on code in PR #23880:
URL: https://github.com/apache/datafusion/pull/23880#discussion_r3926807684


##########
datafusion/spark/src/function/string/quote.rs:
##########
@@ -88,34 +89,62 @@ fn spark_quote_inner(arg: &[ArrayRef]) -> Result<ArrayRef> {
 
 fn quote_array<T: OffsetSizeTrait>(array: &ArrayRef) -> Result<ArrayRef> {
     let str_array = as_generic_string_array::<T>(array)?;
-    let result = str_array
-        .iter()
-        .map(|s| s.map(compute_quote))
-        .collect::<StringArray>();
-    Ok(Arc::new(result))
+    // Slicing an array keeps the whole value buffer and narrows only the
+    // offsets, so measure the data through the offsets rather than through
+    // `value_data()`.
+    let offsets = str_array.value_offsets();
+    let data_len = match (offsets.first(), offsets.last()) {
+        (Some(first), Some(last)) => last.as_usize() - first.as_usize(),
+        _ => 0,
+    };

Review Comment:
   Done in f622ed1c0 — `quote_array` now takes the length directly:
   
   ```rust
   let offsets = str_array.value_offsets();
   let data_len = offsets.last().unwrap().as_usize() - offsets[0].as_usize();
   ```
   
   with a comment recording why the unwrap is sound (an offset buffer holds one 
more entry than the array has rows, so it is never empty).



-- 
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]

Reply via email to