MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / array_remove

Function array_remove

src/expr/src/scalar/func.rs:2765–2789  ·  view source on GitHub ↗
(
    arr: Array<'a>,
    b: Datum<'a>,
    temp_storage: &'a RowArena,
)

Source from the content-addressed store, hash-verified

2763 introduces_nulls = false
2764)]
2765fn array_remove<'a>(
2766 arr: Array<'a>,
2767 b: Datum<'a>,
2768 temp_storage: &'a RowArena,
2769) -> Result<Datum<'a>, EvalError> {
2770 // Zero-dimensional arrays are empty by definition
2771 if arr.dims().len() == 0 {
2772 return Ok(Datum::Array(arr));
2773 }
2774
2775 // array_remove only supports one-dimensional arrays
2776 if arr.dims().len() > 1 {
2777 return Err(EvalError::MultidimensionalArrayRemovalNotSupported);
2778 }
2779
2780 let elems: Vec<_> = arr.elements().iter().filter(|v| v != &b).collect();
2781 let mut dims = arr.dims().into_iter().collect::<Vec<_>>();
2782 // This access is safe because `dims` is guaranteed to be non-empty
2783 dims[0] = ArrayDimension {
2784 lower_bound: 1,
2785 length: elems.len(),
2786 };
2787
2788 Ok(temp_storage.try_make_datum(|packer| packer.try_push_array(&dims, elems))?)
2789}
2790
2791#[sqlfunc(is_infix_op = true)]
2792// TODO(benesch): remove potentially dangerous usage of `as`.

Callers

nothing calls this directly

Calls 10

ArrayClass · 0.85
dimsMethod · 0.80
elementsMethod · 0.80
try_make_datumMethod · 0.80
try_push_arrayMethod · 0.80
lenMethod · 0.45
collectMethod · 0.45
filterMethod · 0.45
iterMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected