Jefffrey commented on code in PR #22390:
URL: https://github.com/apache/datafusion/pull/22390#discussion_r3295681850


##########
datafusion/functions-nested/src/remove.rs:
##########
@@ -468,6 +542,105 @@ fn general_remove<OffsetSize: OffsetSizeTrait>(
     )?))
 }
 
+/// For each element of `list_array[i]`, removes up to `max_removals` 
occurrences
+/// of the scalar needle.
+///
+/// This is a specialized version of `general_remove` for scalar elements that
+/// uses bulk comparison for better performance.
+fn general_remove_with_scalar<OffsetSize: OffsetSizeTrait>(
+    list_array: &GenericListArray<OffsetSize>,
+    scalar_needle: &ScalarValue,
+    max_removals: i64,
+) -> Result<ArrayRef> {
+    if max_removals <= 0 {
+        return Ok(Arc::new(list_array.clone()));
+    }
+
+    let list_field = match list_array.data_type() {
+        DataType::List(field) | DataType::LargeList(field) => field,
+        _ => {
+            return exec_err!(
+                "Expected List or LargeList data type, got {:?}",
+                list_array.data_type()
+            );
+        }
+    };
+
+    let list_offsets = list_array.offsets();
+    let first_offset = list_offsets[0].to_usize().unwrap();
+    let last_offset = list_offsets[list_offsets.len() - 1].to_usize().unwrap();
+    let values_range_len = last_offset - first_offset;
+    let values_slice = list_array.values().slice(first_offset, 
values_range_len);
+    let original_data = values_slice.to_data();
+    let mut offsets = OffsetBufferBuilder::<OffsetSize>::new(list_array.len());
+
+    let mut mutable = MutableArrayData::with_capacities(
+        vec![&original_data],
+        false,
+        Capacities::Array(original_data.len()),
+    );
+    let nulls = list_array.nulls().cloned();
+    let needle = scalar_needle.to_array_of_size(1)?;
+    let keep_mask = arrow_ord::cmp::distinct(&values_slice, 
&Scalar::new(needle))?;
+    let remove_bits = !keep_mask.values();

Review Comment:
   nit: we could use `not_distinct` instead of negating the `distinct` result



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to