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

Function string_agg

src/expr/src/relation/func.rs:239–273  ·  view source on GitHub ↗
(datums: I, temp_storage: &'a RowArena, order_by: &[ColumnOrder])

Source from the content-addressed store, hash-verified

237}
238
239fn string_agg<'a, I>(datums: I, temp_storage: &'a RowArena, order_by: &[ColumnOrder]) -> Datum<'a>
240where
241 I: IntoIterator<Item = Datum<'a>>,
242{
243 const EMPTY_SEP: &str = "";
244
245 let datums = order_aggregate_datums(datums, order_by);
246 let mut sep_value_pairs = datums.into_iter().filter_map(|d| {
247 if d.is_null() {
248 return None;
249 }
250 let mut value_sep = d.unwrap_list().iter();
251 match (value_sep.next().unwrap(), value_sep.next().unwrap()) {
252 (Datum::Null, _) => None,
253 (Datum::String(val), Datum::Null) => Some((EMPTY_SEP, val)),
254 (Datum::String(val), Datum::String(sep)) => Some((sep, val)),
255 _ => unreachable!(),
256 }
257 });
258
259 let mut s = String::default();
260 match sep_value_pairs.next() {
261 // First value not prefixed by its separator
262 Some((_, value)) => s.push_str(value),
263 // If no non-null values sent, return NULL.
264 None => return Datum::Null,
265 }
266
267 for (sep, value) in sep_value_pairs {
268 s.push_str(sep);
269 s.push_str(value);
270 }
271
272 Datum::String(temp_storage.push_string(s))
273}
274
275fn jsonb_agg<'a, I>(datums: I, temp_storage: &'a RowArena, order_by: &[ColumnOrder]) -> Datum<'a>
276where

Callers 1

eval_datumsMethod · 0.85

Calls 9

order_aggregate_datumsFunction · 0.85
StringClass · 0.85
unwrap_listMethod · 0.80
unwrapMethod · 0.80
push_stringMethod · 0.80
into_iterMethod · 0.45
is_nullMethod · 0.45
iterMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected