zhangxffff commented on code in PR #8268:
URL: https://github.com/apache/arrow-datafusion/pull/8268#discussion_r1409001429


##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -1991,6 +1992,71 @@ pub fn array_intersect(args: &[ArrayRef]) -> 
Result<ArrayRef> {
     }
 }
 
+pub fn general_array_distinct<OffsetSize: OffsetSizeTrait>(
+    array: &GenericListArray<OffsetSize>,
+    field: &FieldRef,
+) -> Result<ArrayRef> {
+    let dt = array.value_type();
+    let mut offsets = vec![OffsetSize::usize_as(0)];
+    let mut new_arrays = vec![];
+    let converter = RowConverter::new(vec![SortField::new(dt.clone())])?;
+    // distinct for each list in ListArray
+    for arr in array.iter().flatten() {
+        let values = converter.convert_columns(&[arr])?;
+        let mut rows = Vec::with_capacity(values.num_rows());
+        // sort elements in list and remove duplicates
+        for val in values.iter().sorted().dedup() {
+            rows.push(val);
+        }

Review Comment:
   It seems that using `collect::<Vec<_>>()` can avoid waste memory in vector



##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -1991,6 +1992,71 @@ pub fn array_intersect(args: &[ArrayRef]) -> 
Result<ArrayRef> {
     }
 }
 
+pub fn general_array_distinct<OffsetSize: OffsetSizeTrait>(
+    array: &GenericListArray<OffsetSize>,
+    field: &FieldRef,
+) -> Result<ArrayRef> {
+    let dt = array.value_type();
+    let mut offsets = vec![OffsetSize::usize_as(0)];
+    let mut new_arrays = vec![];
+    let converter = RowConverter::new(vec![SortField::new(dt.clone())])?;
+    // distinct for each list in ListArray
+    for arr in array.iter().flatten() {
+        let values = converter.convert_columns(&[arr])?;

Review Comment:
   why not distinct array in columnar way, `arr` has only one column, using row 
format need extra encoding and decoding



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