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

Function window_aggr_inner

src/expr/src/relation/func.rs:1365–1692  ·  view source on GitHub ↗
(
    mut args: Vec<Datum<'a>>,
    order_by_rows: &Vec<Row>,
    wrapped_aggregate: &AggregateFunc,
    order_by: &[ColumnOrder],
    window_frame: &WindowFrame,
    temp_storage: &'a RowArena,
)

Source from the content-addressed store, hash-verified

1363}
1364
1365fn window_aggr_inner<'a, A>(
1366 mut args: Vec<Datum<'a>>,
1367 order_by_rows: &Vec<Row>,
1368 wrapped_aggregate: &AggregateFunc,
1369 order_by: &[ColumnOrder],
1370 window_frame: &WindowFrame,
1371 temp_storage: &'a RowArena,
1372) -> Vec<Datum<'a>>
1373where
1374 A: OneByOneAggr,
1375{
1376 let length = args.len();
1377 let mut result: Vec<Datum> = Vec::with_capacity(length);
1378
1379 // In this degenerate case, all results would be `wrapped_aggregate.default()` (usually null).
1380 // However, this currently can't happen, because
1381 // - Groups frame mode is currently not supported;
1382 // - Range frame mode is currently supported only for the default frame, which includes the
1383 // current row.
1384 soft_assert_or_log!(
1385 !((matches!(window_frame.units, WindowFrameUnits::Groups)
1386 || matches!(window_frame.units, WindowFrameUnits::Range))
1387 && !window_frame.includes_current_row()),
1388 "window frame without current row"
1389 );
1390
1391 if (matches!(
1392 window_frame.start_bound,
1393 WindowFrameBound::UnboundedPreceding
1394 ) && matches!(window_frame.end_bound, WindowFrameBound::UnboundedFollowing))
1395 || (order_by.is_empty()
1396 && (matches!(window_frame.units, WindowFrameUnits::Groups)
1397 || matches!(window_frame.units, WindowFrameUnits::Range))
1398 && window_frame.includes_current_row())
1399 {
1400 // Either
1401 // - UNBOUNDED frame in both directions, or
1402 // - There is no ORDER BY and the frame is such that the current peer group is included.
1403 // (The current peer group will be the whole partition if there is no ORDER BY.)
1404 // We simply need to compute the aggregate once, on the entire partition, and each input
1405 // row will get this one aggregate value as result.
1406 let result_value =
1407 wrapped_aggregate.eval(args.into_iter().map(|d| (d, Diff::ONE)), temp_storage);
1408 // Every row will get the above aggregate as result.
1409 for _ in 0..length {
1410 result.push(result_value);
1411 }
1412 } else {
1413 fn rows_between_unbounded_preceding_and_current_row<'a, A>(
1414 args: Vec<Datum<'a>>,
1415 result: &mut Vec<Datum<'a>>,
1416 mut one_by_one_aggr: A,
1417 temp_storage: &'a RowArena,
1418 ) where
1419 A: OneByOneAggr,
1420 {
1421 for current_arg in args.into_iter() {
1422 one_by_one_aggr.give(&current_arg);

Callers

nothing calls this directly

Calls 9

includes_current_rowMethod · 0.80
expectMethod · 0.80
lenMethod · 0.45
is_emptyMethod · 0.45
evalMethod · 0.45
mapMethod · 0.45
into_iterMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected