alamb commented on code in PR #7993:
URL: https://github.com/apache/arrow-datafusion/pull/7993#discussion_r1377721418


##########
datafusion/common/src/utils.rs:
##########
@@ -336,16 +337,40 @@ pub fn longest_consecutive_prefix<T: Borrow<usize>>(
     count
 }
 
-/// Wrap an array into a single element `ListArray`.
-/// For example `[1, 2, 3]` would be converted into `[[1, 2, 3]]`
-pub fn wrap_into_list_array(arr: ArrayRef) -> ListArray {
-    let offsets = OffsetBuffer::from_lengths([arr.len()]);
-    ListArray::new(
-        Arc::new(Field::new("item", arr.data_type().to_owned(), true)),
-        offsets,
-        arr,
+/// Wrap arrays into a single element `ListArray`.
+///
+/// Example:
+/// ```
+/// use arrow::array::{Int32Array, ListArray};
+/// use arrow::datatypes::{Int32Type, Field};
+///
+/// let arr1 = Int32Array::from(vec![1, 2, 3]);
+/// let arr2 = Int32Array::from(vec![4, 5, 6]);
+///
+/// let list_arr = datafusion_common::utils::wrap_into_list_array(&[&arr1, 
&arr2]).unwrap();
+///
+/// let expected = ListArray::from_iter_primitive::<Int32Type, _, _>(
+///    vec![
+///     Some(vec![Some(1), Some(2), Some(3)]),
+///     Some(vec![Some(4), Some(5), Some(6)]),
+///    ]
+/// );
+///
+/// assert_eq!(list_arr, expected);
+pub fn wrap_into_list_array(arr: &[&dyn Array]) -> Result<ListArray> {

Review Comment:
   Could we possibly make this API easier to use (require fewer `&`)? 
   
   This looks pretty awkward:
   ```
               wrap_into_list_array(&[&StringArray::from(vec!["rust", 
"world"])]).unwrap();
   ```
   
   Could you make it so it can be called like this?
   ```
               wrap_into_list_array([StringArray::from(vec!["rust", 
"world"])]).unwrap();
   ```
   
   Or perhaps we could make two functions like
   
   ```rust
   pub fn array_to_list_array(arr: ArrayRef) -> ListArray {
   ...
   }
   
   pub fn arrays_to_list_array(arr: impl IntoIterator<Item = ArrayRef>) -> 
ListArray {
   ...
   }
   
   ```
   
   



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

Reply via email to