Dandandan commented on code in PR #8081:
URL: https://github.com/apache/arrow-datafusion/pull/8081#discussion_r1387900450
##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -1820,6 +1822,66 @@ pub fn array_has_all(args: &[ArrayRef]) ->
Result<ArrayRef> {
Ok(Arc::new(boolean_builder.finish()))
}
+/// array_intersect SQL function
+pub fn array_intersect(args: &[ArrayRef]) -> Result<ArrayRef> {
+ assert_eq!(args.len(), 2);
+
+ let first_array = as_list_array(&args[0])?;
+ let second_array = as_list_array(&args[1])?;
+
+ if first_array.value_type() != second_array.value_type() {
+ return Err(DataFusionError::NotImplemented(format!(
+ "array_intersect is not implemented for '{first_array:?}' and
'{second_array:?}'",
+ )));
+ }
+ let dt = first_array.value_type().clone();
+
+ let mut offsets = vec![0];
+ let mut tmp_values = vec![];
+
+ let mut converter = RowConverter::new(vec![SortField::new(dt.clone())])?;
+ for (first_arr, second_arr) in first_array.iter().zip(second_array.iter())
{
+ if let (Some(first_arr), Some(second_arr)) = (first_arr, second_arr) {
+ let l_values = converter.convert_columns(&[first_arr])?;
+ let r_values = converter.convert_columns(&[second_arr])?;
+
+ let mut values_set = HashSet::with_capacity(l_values.num_rows());
+ for l_val in l_values.iter() {
+ values_set.insert(l_val);
+ }
Review Comment:
```suggestion
let values_set: HashSet<_> = l_values.iter().collect();
```
--
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]