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


##########
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:
   I think we can simply get the internal value via iterating the array
   
   ```rust
           let list_arr = as_list_array(&arr).unwrap();
           let row_number = list_arr.len();
           for i in 0..row_number {
               let arr = list_arr.value(i);
               let i64arr = as_primitive_array::<Int64Type>(&arr);
               for v in i64arr.iter() {
                   // v is Option<i64>
               }
           }
   ```
   
   I'm not so familiar with RowConverter and Row, maybe it is more efficient. 
But I think we can try out the correct implementation first and then improve on 
it latter



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