(
arr: Array<'a>,
b: Datum<'a>,
temp_storage: &'a RowArena,
)
| 2763 | introduces_nulls = false |
| 2764 | )] |
| 2765 | fn 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`. |
nothing calls this directly
no test coverage detected