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

Function array_fill

src/expr/src/scalar/func/variadic.rs:248–339  ·  view source on GitHub ↗
(
    &self,
    fill: Datum<'a>,
    dims: Option<Array<'a>>,
    lower_bounds: OptionalArg<Option<Array<'a>>>,
    temp_storage: &'a RowArena,
)

Source from the content-addressed store, hash-verified

246 introduces_nulls = false
247)]
248fn array_fill<'a>(
249 &self,
250 fill: Datum<'a>,
251 dims: Option<Array<'a>>,
252 lower_bounds: OptionalArg<Option<Array<'a>>>,
253 temp_storage: &'a RowArena,
254) -> Result<Datum<'a>, EvalError> {
255 const MAX_SIZE: usize = (1 << 28) - 1;
256 const NULL_ARR_ERR: &str = "dimension array or low bound array";
257 const NULL_ELEM_ERR: &str = "dimension values";
258
259 if matches!(fill, Datum::Array(_)) {
260 return Err(EvalError::Unsupported {
261 feature: "array_fill with arrays".into(),
262 discussion_no: None,
263 });
264 }
265
266 let Some(arr) = dims else {
267 return Err(EvalError::MustNotBeNull(NULL_ARR_ERR.into()));
268 };
269
270 let dimensions = arr
271 .elements()
272 .iter()
273 .map(|d| match d {
274 Datum::Null => Err(EvalError::MustNotBeNull(NULL_ELEM_ERR.into())),
275 d => Ok(usize::cast_from(u32::reinterpret_cast(d.unwrap_int32()))),
276 })
277 .collect::<Result<Vec<_>, _>>()?;
278
279 let lower_bounds = match *lower_bounds {
280 Some(d) => {
281 let Some(arr) = d else {
282 return Err(EvalError::MustNotBeNull(NULL_ARR_ERR.into()));
283 };
284
285 arr.elements()
286 .iter()
287 .map(|l| match l {
288 Datum::Null => Err(EvalError::MustNotBeNull(NULL_ELEM_ERR.into())),
289 l => Ok(isize::cast_from(l.unwrap_int32())),
290 })
291 .collect::<Result<Vec<_>, _>>()?
292 }
293 None => {
294 vec![1isize; dimensions.len()]
295 }
296 };
297
298 if lower_bounds.len() != dimensions.len() {
299 return Err(EvalError::ArrayFillWrongArraySubscripts);
300 }
301
302 let fill_count: usize = dimensions
303 .iter()
304 .cloned()
305 .map(Some)

Callers

nothing calls this directly

Calls 12

elementsMethod · 0.80
unwrap_int32Method · 0.80
checked_mulMethod · 0.80
try_make_datumMethod · 0.80
try_push_arrayMethod · 0.80
mapMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45
flattenMethod · 0.45
reduceMethod · 0.45
collectMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected