jayzhan211 commented on code in PR #7897:
URL: https://github.com/apache/arrow-datafusion/pull/7897#discussion_r1373106243


##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -1478,6 +1480,53 @@ macro_rules! to_string {
     }};
 }
 
+
+/// Array_union SQL function
+pub fn array_union(args: &[ArrayRef]) -> Result<ArrayRef> {
+    if args.len() != 2 {
+        return exec_err!("array_union needs two arguments")
+    }
+    let array1 = &args[0];
+    let array2= &args[1];
+
+    check_datatypes("array_union", &[array1, array2])?;
+    let list1 = as_list_array(array1)?;
+    let list2 = as_list_array(array2)?;
+    eprintln!("{:?}",list1.value_type());
+    match (list1.value_type(), list2.value_type()){
+        (DataType::Null, _) => {
+            Ok(array2.clone())
+        },
+        (_, DataType::Null) => {
+            Ok(array1.clone())
+        }
+        (DataType::List(_), DataType::List(_)) => {
+            let result = concat_internal(args)?;
+            let row_converter = RowConverter::new(vec![
+                SortField::new(
+                    args[0].data_type().clone()
+                )
+            ]
+            )?;
+            let converted = row_converter.convert_columns(&[result])?;

Review Comment:
   ```rust
   let arr1 = ListArray::from_iter_primitive::<Int64Type, _, _>(vec![
               Some(vec![Some(1), Some(2), Some(3)]),
               Some(vec![Some(4), Some(5)]),
               Some(vec![Some(7)]),
           ]);
   
   let arr2 = ListArray::from_iter_primitive::<Int64Type, _, _>(vec![
               Some(vec![Some(4)]),
               Some(vec![Some(4), Some(5)]),
               Some(vec![Some(7), Some(8), Some(9)]),
           ]);
   
   let arr = concat_internal(&[Arc::new(arr1), Arc::new(arr2)]).unwrap();
   ```
   
   ```txt
   arr: ListArray
   [
     PrimitiveArray<Int64> // 1st row
   [
     1,
     2,
     3,
     4,
   ],
     PrimitiveArray<Int64> // 2nd row
   [
     4,
     5,
     4,
     5,
   ],
     PrimitiveArray<Int64> // 3rd row
   [
     7,
     7,
     8,
     9,
   ],
   ]
   ```
   Expected array after union.
   ```txt 
   arr: ListArray
   [
     PrimitiveArray<Int64> // 1st row
   [
     1,
     2,
     3,
     4,
   ],
     PrimitiveArray<Int64> // 2nd row
   [
     4,
     5,
   ],
     PrimitiveArray<Int64> // 3rd row
   [
     7,
     8,
     9,
   ],
   ]
   ```



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