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

Function array_length

src/expr/src/scalar/func.rs:2725–2738  ·  view source on GitHub ↗
(a: Array<'a>, b: i64)

Source from the content-addressed store, hash-verified

2723 introduces_nulls = true
2724)]
2725fn array_length<'a>(a: Array<'a>, b: i64) -> Result<Option<i32>, EvalError> {
2726 let i = match usize::try_from(b) {
2727 Ok(0) | Err(_) => return Ok(None),
2728 Ok(n) => n - 1,
2729 };
2730 Ok(match a.dims().into_iter().nth(i) {
2731 None => None,
2732 Some(dim) => Some(
2733 dim.length
2734 .try_into()
2735 .map_err(|_| EvalError::Int32OutOfRange(dim.length.to_string().into()))?,
2736 ),
2737 })
2738}
2739
2740#[sqlfunc(is_infix_op = true)]
2741// TODO(benesch): remove potentially dangerous usage of `as`.

Callers

nothing calls this directly

Calls 4

dimsMethod · 0.80
into_iterMethod · 0.45
try_intoMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected