You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/05/25 23:54:31 UTC

(datafusion) branch main updated: perf: optimize array_remove for scalar needle (#22390)

This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new a87bdc9a90 perf: optimize array_remove for scalar needle (#22390)
a87bdc9a90 is described below

commit a87bdc9a9038c14d7b52ece779668c05d6411949
Author: linfeng <33...@users.noreply.github.com>
AuthorDate: Tue May 26 07:34:33 2026 +0800

    perf: optimize array_remove for scalar needle (#22390)
    
    ## Which issue does this PR close?
    
    <!--
    We generally require a GitHub issue to be filed for all bug fixes and
    enhancements and this helps us generate change logs for our releases.
    You can link an issue to this PR using the GitHub syntax. For example
    `Closes #123` indicates that this PR will close issue #123.
    -->
    
    - Closes #.
    
    ## Rationale for this change
    
    <!--
    Why are you proposing this change? If this is already explained clearly
    in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand
    your changes and offer better suggestions for fixes.
    -->
    
    Similar to #22387 (array_replace scalar optimization)
    
    `array_remove` / `array_remove_n` / `array_remove_all` perform
    element-wise comparison by invoking `compare_element_to_list` against
    each row's sub-array individually. When the needle is a scalar, this can
    be optimized by performing a single vectorized `distinct` comparison
    over the entire flattened values buffer.
    
    
    ## What changes are included in this PR?
    
    
    - Add a specialized removal kernel (`general_remove_with_scalar`) that
    uses `arrow_ord::cmp::distinct` with `Scalar` wrapper for a single bulk
    comparison pass over the flat values buffer.
    - Extend SLT tests with multi-row scalar-argument coverage,
    NULL-containing arrays, empty-array edge cases, boundary `n` values, and
    LargeList type coverage.
    
    <!--
    There is no need to duplicate the description in the issue here but it
    is sometimes worth providing a summary of the individual changes in this
    PR.
    -->
    
    ### Benchmarks
    ```
    group                                                                    main                                   optimized
    -----                                                                    ----                                   ---------
    array_remove_all_int64/remove/list size: 10, num_rows: 4000              4.35   856.8±97.81µs        ? ?/sec    1.00    196.9±4.48µs        ? ?/sec
    array_remove_all_int64/remove/list size: 100, num_rows: 10000            1.90      5.5±0.09ms        ? ?/sec    1.00      2.9±0.09ms        ? ?/sec
    array_remove_all_int64/remove/list size: 500, num_rows: 10000            1.35     19.2±0.21ms        ? ?/sec    1.00     14.2±0.48ms        ? ?/sec
    array_remove_all_int64_nested/remove/list size: 10, num_rows: 4000       1.00      7.1±0.12ms        ? ?/sec    1.04      7.4±0.12ms        ? ?/sec
    array_remove_all_int64_nested/remove/list size: 100, num_rows: 3000      1.00     36.5±0.39ms        ? ?/sec    1.05     38.3±2.61ms        ? ?/sec
    array_remove_all_int64_nested/remove/list size: 300, num_rows: 1500      1.01     53.5±2.26ms        ? ?/sec    1.00     53.0±0.99ms        ? ?/sec
    array_remove_boolean/remove/list size: 10, num_rows: 4000                3.83    813.9±7.08µs        ? ?/sec    1.00    212.4±2.28µs        ? ?/sec
    array_remove_boolean/remove/list size: 100, num_rows: 10000              2.73      3.7±0.03ms        ? ?/sec    1.00  1364.7±177.83µs        ? ?/sec
    array_remove_boolean/remove/list size: 500, num_rows: 10000              2.34      9.8±0.14ms        ? ?/sec    1.00      4.2±0.25ms        ? ?/sec
    array_remove_fixed_size_binary/remove/list size: 10, num_rows: 4000      3.16   918.2±16.76µs        ? ?/sec    1.00    290.6±9.79µs        ? ?/sec
    array_remove_fixed_size_binary/remove/list size: 100, num_rows: 10000    1.56      6.9±0.13ms        ? ?/sec    1.00      4.4±0.15ms        ? ?/sec
    array_remove_fixed_size_binary/remove/list size: 500, num_rows: 10000    1.17     27.7±0.84ms        ? ?/sec    1.00     23.6±2.04ms        ? ?/sec
    array_remove_int64/remove/list size: 10, num_rows: 4000                  4.55    825.7±6.30µs        ? ?/sec    1.00    181.3±4.32µs        ? ?/sec
    array_remove_int64/remove/list size: 100, num_rows: 10000                3.35      3.8±0.11ms        ? ?/sec    1.00  1135.6±54.87µs        ? ?/sec
    array_remove_int64/remove/list size: 500, num_rows: 10000                2.04     10.3±0.35ms        ? ?/sec    1.00      5.1±0.39ms        ? ?/sec
    array_remove_int64_nested/remove/list size: 10, num_rows: 4000           1.00      7.1±0.18ms        ? ?/sec    1.02      7.2±0.07ms        ? ?/sec
    array_remove_int64_nested/remove/list size: 100, num_rows: 3000          1.00     36.1±1.35ms        ? ?/sec    1.07     38.5±3.67ms        ? ?/sec
    array_remove_int64_nested/remove/list size: 300, num_rows: 1500          1.00     51.7±0.57ms        ? ?/sec    1.05     54.1±2.13ms        ? ?/sec
    array_remove_n_int64/remove/list size: 10, num_rows: 4000                4.43    845.3±5.00µs        ? ?/sec    1.00    190.6±2.84µs        ? ?/sec
    array_remove_n_int64/remove/list size: 100, num_rows: 10000              2.29      4.7±0.11ms        ? ?/sec    1.00      2.0±0.12ms        ? ?/sec
    array_remove_n_int64/remove/list size: 500, num_rows: 10000              1.63     14.8±0.42ms        ? ?/sec    1.00      9.0±0.51ms        ? ?/sec
    array_remove_n_int64_nested/remove/list size: 10, num_rows: 4000         1.00      7.0±0.09ms        ? ?/sec    1.29      8.9±3.44ms        ? ?/sec
    array_remove_n_int64_nested/remove/list size: 100, num_rows: 3000        1.00     36.6±0.42ms        ? ?/sec    1.03     37.7±0.68ms        ? ?/sec
    array_remove_n_int64_nested/remove/list size: 300, num_rows: 1500        1.00     52.7±3.68ms        ? ?/sec    1.03     54.5±4.49ms        ? ?/sec
    array_remove_strings/remove/list size: 10, num_rows: 4000                2.50  1144.6±21.95µs        ? ?/sec    1.00   457.0±14.15µs        ? ?/sec
    array_remove_strings/remove/list size: 100, num_rows: 10000              1.42     10.5±1.16ms        ? ?/sec    1.00      7.4±0.34ms        ? ?/sec
    array_remove_strings/remove/list size: 500, num_rows: 10000              1.12     39.8±0.91ms        ? ?/sec    1.00     35.5±1.51ms        ? ?/sec
    ```
    
    ## Are these changes tested?
    
    <!--
    We typically require tests for all PRs in order to:
    1. Prevent the code from being accidentally broken by subsequent changes
    2. Serve as another way to document the expected behavior of the code
    
    If tests are not included in your PR, please explain why (for example,
    are they covered by existing tests)?
    -->
    
    Yes, existing and new SLT edge-case tests in `array_remove.slt`.
    
    ## Are there any user-facing changes?
    
    No.
    
    <!--
    If there are user-facing changes then we may require documentation to be
    updated before approving the PR.
    -->
    
    <!--
    If there are any breaking changes to public APIs, please add the `api
    change` label.
    -->
---
 datafusion/functions-nested/src/remove.rs          | 231 ++++++++++++++++++---
 .../sqllogictest/test_files/array/array_remove.slt |  85 +++++++-
 2 files changed, 286 insertions(+), 30 deletions(-)

diff --git a/datafusion/functions-nested/src/remove.rs b/datafusion/functions-nested/src/remove.rs
index d0f838ddad..1dde2aa762 100644
--- a/datafusion/functions-nested/src/remove.rs
+++ b/datafusion/functions-nested/src/remove.rs
@@ -18,16 +18,17 @@
 //! [`ScalarUDFImpl`] definitions for array_remove, array_remove_n, array_remove_all functions.
 
 use crate::utils;
-use crate::utils::make_scalar_function;
 use arrow::array::{
-    Array, ArrayRef, Capacities, GenericListArray, MutableArrayData, OffsetSizeTrait,
-    cast::AsArray, make_array,
+    Array, ArrayRef, Capacities, GenericListArray, MutableArrayData, OffsetBufferBuilder,
+    OffsetSizeTrait, Scalar, cast::AsArray, make_array,
 };
 use arrow::buffer::{NullBuffer, OffsetBuffer};
 use arrow::datatypes::{DataType, FieldRef};
 use datafusion_common::cast::as_int64_array;
 use datafusion_common::utils::ListCoercion;
-use datafusion_common::{Result, exec_err, internal_err, utils::take_function_args};
+use datafusion_common::{
+    Result, ScalarValue, exec_err, internal_err, utils::take_function_args,
+};
 use datafusion_expr::{
     ArrayFunctionArgument, ArrayFunctionSignature, ColumnarValue, Documentation,
     ScalarFunctionArgs, ScalarUDFImpl, Signature, TypeSignature, Volatility,
@@ -113,7 +114,24 @@ impl ScalarUDFImpl for ArrayRemove {
     }
 
     fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
-        make_scalar_function(array_remove_inner)(&args.args)
+        let [list_arg, element_arg] = take_function_args(self.name(), &args.args)?;
+        let num_rows = args.number_rows;
+        let list_array = list_arg.to_array(num_rows)?;
+        match element_arg {
+            ColumnarValue::Scalar(scalar_element)
+                if !scalar_element.is_null()
+                    && !scalar_element.data_type().is_nested() =>
+            {
+                let result =
+                    array_remove_with_scalar_args(&list_array, scalar_element, 1i64)?;
+                Ok(ColumnarValue::Array(result))
+            }
+            element_arg => {
+                let element_array = element_arg.to_array(num_rows)?;
+                let result = array_remove_internal(&list_array, &element_array, &[1])?;
+                Ok(ColumnarValue::Array(result))
+            }
+        }
     }
 
     fn aliases(&self) -> &[String] {
@@ -214,7 +232,40 @@ impl ScalarUDFImpl for ArrayRemoveN {
     }
 
     fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
-        make_scalar_function(array_remove_n_inner)(&args.args)
+        let [list_arg, element_arg, max_arg] =
+            take_function_args(self.name(), &args.args)?;
+        let num_rows = args.number_rows;
+        let list_array = list_arg.to_array(num_rows)?;
+        match (element_arg, max_arg) {
+            (
+                ColumnarValue::Scalar(scalar_element),
+                ColumnarValue::Scalar(scalar_max),
+            ) if !scalar_element.is_null() && !scalar_element.data_type().is_nested() => {
+                let ScalarValue::Int64(Some(n)) = scalar_max else {
+                    // null max means no remove
+                    return Ok(ColumnarValue::Array(list_array));
+                };
+                let result =
+                    array_remove_with_scalar_args(&list_array, scalar_element, *n)?;
+                Ok(ColumnarValue::Array(result))
+            }
+            (element_arg, max_arg) => {
+                let element_array = element_arg.to_array(num_rows)?;
+                let max_array = max_arg.to_array(num_rows)?;
+                let max_array = as_int64_array(&max_array)?;
+                let arr_n = (0..max_array.len())
+                    .map(|i| {
+                        if max_array.is_null(i) {
+                            0
+                        } else {
+                            max_array.value(i)
+                        }
+                    })
+                    .collect::<Vec<_>>();
+                let result = array_remove_internal(&list_array, &element_array, &arr_n)?;
+                Ok(ColumnarValue::Array(result))
+            }
+        }
     }
 
     fn aliases(&self) -> &[String] {
@@ -304,7 +355,25 @@ impl ScalarUDFImpl for ArrayRemoveAll {
     }
 
     fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
-        make_scalar_function(array_remove_all_inner)(&args.args)
+        let [list_arg, element_arg] = take_function_args(self.name(), &args.args)?;
+        let num_rows = args.number_rows;
+        let list_array = list_arg.to_array(num_rows)?;
+        match element_arg {
+            ColumnarValue::Scalar(scalar_element)
+                if !scalar_element.is_null()
+                    && !scalar_element.data_type().is_nested() =>
+            {
+                let result =
+                    array_remove_with_scalar_args(&list_array, scalar_element, i64::MAX)?;
+                Ok(ColumnarValue::Array(result))
+            }
+            element_arg => {
+                let element_array = element_arg.to_array(num_rows)?;
+                let result =
+                    array_remove_internal(&list_array, &element_array, &[i64::MAX])?;
+                Ok(ColumnarValue::Array(result))
+            }
+        }
     }
 
     fn aliases(&self) -> &[String] {
@@ -316,27 +385,6 @@ impl ScalarUDFImpl for ArrayRemoveAll {
     }
 }
 
-fn array_remove_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
-    let [array, element] = take_function_args("array_remove", args)?;
-
-    let arr_n = vec![1; array.len()];
-    array_remove_internal(array, element, &arr_n)
-}
-
-fn array_remove_n_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
-    let [array, element, max] = take_function_args("array_remove_n", args)?;
-
-    let arr_n = as_int64_array(max)?.values().to_vec();
-    array_remove_internal(array, element, &arr_n)
-}
-
-fn array_remove_all_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
-    let [array, element] = take_function_args("array_remove_all", args)?;
-
-    let arr_n = vec![i64::MAX; array.len()];
-    array_remove_internal(array, element, &arr_n)
-}
-
 fn array_remove_internal(
     array: &ArrayRef,
     element_array: &ArrayRef,
@@ -357,6 +405,28 @@ fn array_remove_internal(
     }
 }
 
+/// Fast path for `array_remove` when the needle is a non-null, non-nested scalar.
+/// Dispatches to the bulk `not_distinct` comparison kernel.
+fn array_remove_with_scalar_args(
+    array: &ArrayRef,
+    scalar_needle: &ScalarValue,
+    max_removals: i64,
+) -> Result<ArrayRef> {
+    match array.data_type() {
+        DataType::List(_) => {
+            let list_array = array.as_list::<i32>();
+            general_remove_with_scalar::<i32>(list_array, scalar_needle, max_removals)
+        }
+        DataType::LargeList(_) => {
+            let list_array = array.as_list::<i64>();
+            general_remove_with_scalar::<i64>(list_array, scalar_needle, max_removals)
+        }
+        array_type => exec_err!(
+            "array_remove/array_remove_n/array_remove_all does not support type '{array_type}'."
+        ),
+    }
+}
+
 /// For each element of `list_array[i]`, removed up to `arr_n[i]` occurrences
 /// of `element_array[i]`.
 ///
@@ -411,7 +481,11 @@ fn general_remove<OffsetSize: OffsetSizeTrait>(
         let start = offset_window[0].to_usize().unwrap();
         let end = offset_window[1].to_usize().unwrap();
         // n is the number of elements to remove in this row
-        let n = arr_n[row_index];
+        let n = if arr_n.len() == 1 {
+            arr_n[0]
+        } else {
+            arr_n[row_index]
+        };
 
         // compare each element in the list, `false` means the element matches and should be removed
         let eq_array = utils::compare_element_to_list(
@@ -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 remove_mask = arrow_ord::cmp::not_distinct(&values_slice, &Scalar::new(needle))?;
+    let remove_bits = remove_mask.values();
+
+    for (row_index, offset_window) in list_offsets.windows(2).enumerate() {
+        if nulls.as_ref().is_some_and(|nulls| nulls.is_null(row_index)) {
+            offsets.push_length(0);
+            continue;
+        }
+
+        let start = offset_window[0].to_usize().unwrap() - first_offset;
+        let end = offset_window[1].to_usize().unwrap() - first_offset;
+        let row_len = end - start;
+
+        let row_remove_bits = remove_bits.slice(start, row_len);
+        let num_to_remove = row_remove_bits.count_set_bits();
+
+        if num_to_remove == 0 {
+            mutable.extend(0, start, end);
+            offsets.push_length(row_len);
+            continue;
+        }
+
+        let removals_to_apply = max_removals.min(num_to_remove as i64) as usize;
+
+        // Iterate only over the removal positions via set_indices. This is
+        // efficient when the number of removals is small relative to the row
+        // length (common case), since it skips over retained elements.
+        let mut removed = 0usize;
+        let mut copied = 0usize;
+        let mut prev_end = start;
+        for remove_pos in row_remove_bits.set_indices() {
+            let abs_pos = start + remove_pos;
+            if abs_pos > prev_end {
+                mutable.extend(0, prev_end, abs_pos);
+                copied += abs_pos - prev_end;
+            }
+            prev_end = abs_pos + 1;
+            removed += 1;
+            if removed == removals_to_apply {
+                break;
+            }
+        }
+        // Copy the remaining tail after the last removal
+        if prev_end < end {
+            mutable.extend(0, prev_end, end);
+            copied += end - prev_end;
+        }
+
+        offsets.push_length(copied);
+    }
+
+    let new_values = make_array(mutable.freeze());
+    Ok(Arc::new(GenericListArray::<OffsetSize>::try_new(
+        Arc::clone(list_field),
+        offsets.finish(),
+        new_values,
+        nulls,
+    )?))
+}
+
 #[cfg(test)]
 mod tests {
     use crate::remove::{ArrayRemove, ArrayRemoveAll, ArrayRemoveN};
diff --git a/datafusion/sqllogictest/test_files/array/array_remove.slt b/datafusion/sqllogictest/test_files/array/array_remove.slt
index c3ce7073ec..195f7a0f33 100644
--- a/datafusion/sqllogictest/test_files/array/array_remove.slt
+++ b/datafusion/sqllogictest/test_files/array/array_remove.slt
@@ -266,6 +266,13 @@ select array_remove_n(make_array(1, 2, 2, 1, 1), NULL, 2),
 ----
 NULL [1, 1, 1]
 
+# array_remove_n with null max scalar
+query ??
+select array_remove_n(make_array(1, 2, 2, 1, 1), 2, NULL),
+       array_remove_n(arrow_cast(make_array(1, 2, 2, 1, 1), 'LargeList(Int64)'), 2, NULL);
+----
+[1, 2, 2, 1, 1] [1, 2, 2, 1, 1]
+
 # array_remove_n with null element scalar (LargeList)
 query ??
 select array_remove_n(arrow_cast(make_array(1, 2, 2, 1, 1), 'LargeList(Int64)'), NULL, 2),
@@ -279,12 +286,14 @@ select array_remove_n(column1, column2, column3) from (values
   (make_array(1, 2, 2, 1, 1), 2, 2),
   (make_array(3, 4, 4, 3, 3), null, 2),
   (make_array(5, 6, 6, 5, 5), 6, 1),
+  (make_array(7, 8, 8, 7, 7), 8, null),
   (null, 1, 1)
 ) as t(column1, column2, column3);
 ----
 [1, 1, 1]
 NULL
 [5, 6, 5, 5]
+[7, 8, 8, 7, 7]
 NULL
 
 # array_remove_n with null element from column (LargeList)
@@ -292,12 +301,14 @@ query ?
 select array_remove_n(column1, column2, column3) from (values
   (arrow_cast(make_array(1, 2, 2, 1, 1), 'LargeList(Int64)'), 2, 2),
   (arrow_cast(make_array(3, 4, 4, 3, 3), 'LargeList(Int64)'), null, 2),
-  (arrow_cast(make_array(5, 6, 6, 5, 5), 'LargeList(Int64)'), 6, 1)
+  (arrow_cast(make_array(5, 6, 6, 5, 5), 'LargeList(Int64)'), 6, 1),
+  (arrow_cast(make_array(7, 8, 8, 7, 7), 'LargeList(Int64)'), 8, null)
 ) as t(column1, column2, column3);
 ----
 [1, 1, 1]
 NULL
 [5, 6, 5, 5]
+[7, 8, 8, 7, 7]
 
 # array_remove_n scalar function #1
 query ???
@@ -537,4 +548,76 @@ select array_remove_all(make_array([1, 2, 3], [4, 5, 6], [4, 5, 6], [10, 11, 12]
 [[1, 2, 3], [4, 5, 6], [4, 5, 6], [10, 11, 12], [13, 14, 15], [10, 11, 12], [10, 11, 12], [19, 20, 21], [19, 20, 21], [19, 20, 21], [22, 23, 24]] [[28, 29, 30], [31, 32, 33], [34, 35, 36], [28, 29, 30], [31, 32, 33], [34, 35, 36], [28, 29, 30], [31, 32, 33], [34, 35, 36], [28, 29, 30]]
 
 
+# array_remove scalar arguments over multiple input rows
+query ???
+select
+  array_remove(column1, 2),
+  array_remove_n(column1, 2, 2),
+  array_remove_all(column1, 2)
+from (
+  values
+    (make_array(1, 2, 2, 3, 2, 1, 4)),
+    (make_array(42, 2, 55, 63, 2))
+) as t(column1);
+----
+[1, 2, 3, 2, 1, 4] [1, 3, 2, 1, 4] [1, 3, 1, 4]
+[42, 55, 63, 2] [42, 55, 63] [42, 55, 63]
+
+# array_remove with elements containing NULLs — scalar path preserves NULLs
+query ???
+select
+  array_remove(column1, 2),
+  array_remove_n(column1, 2, 2),
+  array_remove_all(column1, 2)
+from (
+  values
+    (make_array(1, 2, NULL, 3, 2, NULL, 4)),
+    (make_array(42, 2, NULL, 63, 2))
+) as t(column1);
+----
+[1, NULL, 3, 2, NULL, 4] [1, NULL, 3, NULL, 4] [1, NULL, 3, NULL, 4]
+[42, NULL, 63, 2] [42, NULL, 63] [42, NULL, 63]
+
+# array_remove_n with n exceeding match count
+query ?
+select array_remove_n(make_array(1, 2, 2, 3), 2, 100);
+----
+[1, 3]
+
+# array_remove_n with n=0 and n=-1 (no removal)
+query ??
+select
+  array_remove_n(make_array(1, 2, 2, 3), 2, 0),
+  array_remove_n(make_array(1, 2, 2, 3), 2, -1);
+----
+[1, 2, 2, 3] [1, 2, 2, 3]
+
+# array_remove on empty arrays
+query ??
+select
+  array_remove(arrow_cast(make_array(), 'List(Int64)'), 1),
+  array_remove_all(arrow_cast(make_array(), 'List(Int64)'), 1);
+----
+[] []
+
+# array_remove needle not found — array unchanged
+query ?
+select array_remove_all(make_array(1, 2, 3, 4, 5), 99);
+----
+[1, 2, 3, 4, 5]
+
+# array_remove all elements match
+query ?
+select array_remove_all(make_array(7, 7, 7, 7), 7);
+----
+[]
+
+# LargeList scalar path edge cases
+query ??
+select
+  array_remove_all(arrow_cast(make_array(1, 1, 1), 'LargeList(Int64)'), 1),
+  array_remove_n(arrow_cast(make_array(1, 1, 1), 'LargeList(Int64)'), 1, 2);
+----
+[] [1]
+
 include ./cleanup.slt.part


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org