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

Method build_basic_aggregate

src/compute/src/render/reduce.rs:481–773  ·  view source on GitHub ↗

Build the dataflow to compute a single basic aggregation. This method also applies distinctness if required.

(
        &self,
        input: VecCollection<'s, T, (Row, Row), Diff>,
        index: usize,
        aggr: &AggregateExpr,
        validating: bool,
        key_arity: usize,
        mfp_after: Optio

Source from the content-addressed store, hash-verified

479 ///
480 /// This method also applies distinctness if required.
481 fn build_basic_aggregate<'s>(
482 &self,
483 input: VecCollection<'s, T, (Row, Row), Diff>,
484 index: usize,
485 aggr: &AggregateExpr,
486 validating: bool,
487 key_arity: usize,
488 mfp_after: Option<SafeMfpPlan>,
489 fused_unnest_list: bool,
490 ) -> (
491 RowRowArrangement<'s, T>,
492 Option<VecCollection<'s, T, DataflowErrorSer, Diff>>,
493 ) {
494 let AggregateExpr {
495 func,
496 expr: _,
497 distinct,
498 } = aggr.clone();
499
500 // Extract the value we were asked to aggregate over.
501 let mut partial = input.map(move |(key, row)| {
502 let mut row_builder = SharedRow::get();
503 let value = row.iter().nth(index).unwrap();
504 row_builder.packer().push(value);
505 (key, row_builder.clone())
506 });
507
508 let mut err_output = None;
509
510 // If `distinct` is set, we restrict ourselves to the distinct `(key, val)`.
511 if distinct {
512 // We map `(Row, Row)` to `Row` to take advantage of `Row*Spine` types.
513 let pairer = Pairer::new(key_arity);
514 let keyed = partial.map(move |(key, val)| pairer.merge(&key, &val));
515 if validating {
516 let (oks, errs) = self
517 .build_reduce_inaccumulable_distinct::<
518 RowValBuilder<Result<(), String>, _, _>,
519 RowValSpine<Result<(), String>, _, _>,
520 >(keyed, None)
521 .as_collection(|k, v| {
522 (
523 k.to_row(),
524 v.as_ref()
525 .map(|&()| ())
526 .map_err(|m| m.as_str().into()),
527 )
528 })
529 .map_fallible::<
530 CapacityContainerBuilder<_>,
531 CapacityContainerBuilder<_>,
532 _,
533 _,
534 _,
535 >(
536 "Demux Errors",
537 move |(key_val, result)| match result {
538 Ok(()) => Ok(pairer.split(&key_val)),

Callers 2

Calls 15

evaluate_mfp_afterFunction · 0.85
unwrapMethod · 0.80
packerMethod · 0.80
as_collectionMethod · 0.80
is_noneMethod · 0.80
is_someMethod · 0.80
error_loggerMethod · 0.80
evaluate_innerMethod · 0.80
getFunction · 0.50
cloneMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected