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

Function array_create_scalar

src/expr/src/scalar/func.rs:2518–2534  ·  view source on GitHub ↗

Constructs a new zero or one dimensional array out of an arbitrary number of scalars. If `datums` is empty, constructs a zero-dimensional array. Otherwise, constructs a one dimensional array whose lower bound is one and whose length is equal to `datums.len()`.

(
    datums: &[Datum<'a>],
    temp_storage: &'a RowArena,
)

Source from the content-addressed store, hash-verified

2516/// constructs a one dimensional array whose lower bound is one and whose length
2517/// is equal to `datums.len()`.
2518fn array_create_scalar<'a>(
2519 datums: &[Datum<'a>],
2520 temp_storage: &'a RowArena,
2521) -> Result<Datum<'a>, EvalError> {
2522 let mut dims = &[ArrayDimension {
2523 lower_bound: 1,
2524 length: datums.len(),
2525 }][..];
2526 if datums.is_empty() {
2527 // Per PostgreSQL, empty arrays are represented with zero dimensions,
2528 // not one dimension of zero length. We write this condition a little
2529 // strangely to satisfy the borrow checker while avoiding an allocation.
2530 dims = &[];
2531 }
2532 let datum = temp_storage.try_make_datum(|packer| packer.try_push_array(dims, datums))?;
2533 Ok(datum)
2534}
2535
2536fn stringify_datum<'a, B>(
2537 buf: &mut B,

Callers 2

array_createFunction · 0.85
evalMethod · 0.85

Calls 4

try_make_datumMethod · 0.80
try_push_arrayMethod · 0.80
lenMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected