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

Function generate_subscripts_array

src/expr/src/relation/func.rs:3111–3145  ·  view source on GitHub ↗
(
    a: Datum,
    dim: i32,
)

Source from the content-addressed store, hash-verified

3109}
3110
3111fn generate_subscripts_array(
3112 a: Datum,
3113 dim: i32,
3114) -> Result<Box<dyn Iterator<Item = (Row, Diff)>>, EvalError> {
3115 if dim <= 0 {
3116 return Ok(Box::new(iter::empty()));
3117 }
3118
3119 match a.unwrap_array().dims().into_iter().nth(
3120 (dim - 1)
3121 .try_into()
3122 .map_err(|_| EvalError::Int32OutOfRange((dim - 1).to_string().into()))?,
3123 ) {
3124 Some(requested_dim) => {
3125 let lower_bound: i32 = requested_dim.lower_bound.try_into().map_err(|_| {
3126 EvalError::Int32OutOfRange(requested_dim.lower_bound.to_string().into())
3127 })?;
3128 // The subscripts run from the lower bound to the upper bound,
3129 // inclusive. The upper bound is `lower_bound + length - 1`.
3130 let length: i32 = requested_dim
3131 .length
3132 .try_into()
3133 .map_err(|_| EvalError::Int32OutOfRange(requested_dim.length.to_string().into()))?;
3134 let upper_bound = lower_bound.checked_add(length - 1).ok_or_else(|| {
3135 EvalError::Int32OutOfRange(requested_dim.length.to_string().into())
3136 })?;
3137 Ok(Box::new(generate_series::<i32>(
3138 lower_bound,
3139 upper_bound,
3140 1,
3141 )?))
3142 }
3143 None => Ok(Box::new(iter::empty())),
3144 }
3145}
3146
3147fn unnest_array<'a>(a: Datum<'a>) -> impl Iterator<Item = (Row, Diff)> + 'a {
3148 a.unwrap_array()

Callers 1

evalMethod · 0.85

Calls 6

dimsMethod · 0.80
unwrap_arrayMethod · 0.80
into_iterMethod · 0.45
try_intoMethod · 0.45
to_stringMethod · 0.45
checked_addMethod · 0.45

Tested by

no test coverage detected