comphead commented on code in PR #7897:
URL: https://github.com/apache/arrow-datafusion/pull/7897#discussion_r1367772395
##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -1478,6 +1478,28 @@ macro_rules! to_string {
}};
}
+
+/// Array_union SQL function
+pub fn array_union(args: &[ArrayRef]) -> Result<ArrayRef> {
Review Comment:
Please add some check here in case of `args` is of unexpected size
##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -1478,6 +1478,28 @@ macro_rules! to_string {
}};
}
+
+/// Array_union SQL function
+pub fn array_union(args: &[ArrayRef]) -> Result<ArrayRef> {
+ let array1 = &args[0];
+ let array2= &args[1];
+
+ check_datatypes("array_union", &[array1, array2])?;
+ let list1 = as_list_array(array1)?;
Review Comment:
Wondering can we reuse `.data_type()` on `array1` level so we can get rid of
unneccessary conversion
##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -1478,6 +1478,28 @@ macro_rules! to_string {
}};
}
+
+/// Array_union SQL function
+pub fn array_union(args: &[ArrayRef]) -> Result<ArrayRef> {
+ 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)?;
+ match (list1.value_type(), list2.value_type()){
+ (DataType::Null, _) => {
+ Ok(array2.clone())
+ },
+ (_, DataType::Null) => {
+ Ok(array1.clone())
+ }
+ (DataType::List(_), DataType::List(_)) => concat_internal(args),
+ _ => return exec_err!("can only concatenate lists")
Review Comment:
```suggestion
_ => return exec_err!("array_union can only concatenate lists")
```
##########
datafusion/sqllogictest/test_files/array.slt:
##########
@@ -1741,6 +1741,30 @@ select array_to_string(make_array(), ',')
----
(empty)
+
+## array_union (aliases: `list_union`)
+
+# array_union scalar function #1
+query TTT
+select array_union([1, 2, 3, 4], [5, 6, 3, 4]);
Review Comment:
Please add tests with nulls and cases when array sizes are not the same
##########
docs/source/user-guide/expressions.md:
##########
@@ -237,6 +237,7 @@ Unlike to some databases the math functions in Datafusion
works the same way as
| array_replace_all(array, from, to) | Replaces all occurrences of the
specified element with another specified element. `array_replace_all([1, 2, 2,
3, 2, 1, 4], 2, 5) -> [1, 5, 5, 3, 5, 1, 4]` |
| array_slice(array, index) | Returns a slice of the array.
`array_slice([1, 2, 3, 4, 5, 6, 7, 8], 3, 6) -> [3, 4, 5, 6]`
|
| array_to_string(array, delimiter) | Converts each element to its text
representation. `array_to_string([1, 2, 3, 4], ',') -> 1,2,3,4`
|
+| array_union(array1, array2) | CReturns an array of the elements in
the union of array1 and array2 without duplicates. `array_union([1, 2, 3, 4],
[5, 6, 3, 4]) -> [1, 2, 3, 4, 5, 6]`
Review Comment:
```suggestion
| array_union(array1, array2) | Returns an array of the elements
in the union of array1 and array2 without duplicates. `array_union([1, 2, 3,
4], [5, 6, 3, 4]) -> [1, 2, 3, 4, 5, 6]`
```
--
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]