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

Method on_unique

src/expr/src/relation.rs:2571–3074  ·  view source on GitHub ↗

Returns an expression that computes `self` on a group that has exactly one row. Instead of performing a `Reduce` with `self`, one can perform a `Map` with the expression returned by `on_unique`, which is cheaper. (See `ReduceElision`.)

(&self, input_type: &[ReprColumnType])

Source from the content-addressed store, hash-verified

2569 /// Instead of performing a `Reduce` with `self`, one can perform a `Map` with the expression
2570 /// returned by `on_unique`, which is cheaper. (See `ReduceElision`.)
2571 pub fn on_unique(&self, input_type: &[ReprColumnType]) -> MirScalarExpr {
2572 match &self.func {
2573 // Count is one if non-null, and zero if null.
2574 AggregateFunc::Count => self
2575 .expr
2576 .clone()
2577 .call_unary(UnaryFunc::IsNull(crate::func::IsNull))
2578 .if_then_else(
2579 MirScalarExpr::literal_ok(Datum::Int64(0), ReprScalarType::Int64),
2580 MirScalarExpr::literal_ok(Datum::Int64(1), ReprScalarType::Int64),
2581 ),
2582
2583 // SumInt16 takes Int16s as input, but outputs Int64s.
2584 AggregateFunc::SumInt16 => self
2585 .expr
2586 .clone()
2587 .call_unary(UnaryFunc::CastInt16ToInt64(scalar_func::CastInt16ToInt64)),
2588
2589 // SumInt32 takes Int32s as input, but outputs Int64s.
2590 AggregateFunc::SumInt32 => self
2591 .expr
2592 .clone()
2593 .call_unary(UnaryFunc::CastInt32ToInt64(scalar_func::CastInt32ToInt64)),
2594
2595 // SumInt64 takes Int64s as input, but outputs numerics.
2596 AggregateFunc::SumInt64 => self.expr.clone().call_unary(UnaryFunc::CastInt64ToNumeric(
2597 scalar_func::CastInt64ToNumeric(Some(NumericMaxScale::ZERO)),
2598 )),
2599
2600 // SumUInt16 takes UInt16s as input, but outputs UInt64s.
2601 AggregateFunc::SumUInt16 => self.expr.clone().call_unary(
2602 UnaryFunc::CastUint16ToUint64(scalar_func::CastUint16ToUint64),
2603 ),
2604
2605 // SumUInt32 takes UInt32s as input, but outputs UInt64s.
2606 AggregateFunc::SumUInt32 => self.expr.clone().call_unary(
2607 UnaryFunc::CastUint32ToUint64(scalar_func::CastUint32ToUint64),
2608 ),
2609
2610 // SumUInt64 takes UInt64s as input, but outputs numerics.
2611 AggregateFunc::SumUInt64 => {
2612 self.expr.clone().call_unary(UnaryFunc::CastUint64ToNumeric(
2613 scalar_func::CastUint64ToNumeric(Some(NumericMaxScale::ZERO)),
2614 ))
2615 }
2616
2617 // JsonbAgg takes _anything_ as input, but must output a Jsonb array.
2618 AggregateFunc::JsonbAgg { .. } => MirScalarExpr::call_variadic(
2619 JsonbBuildArray,
2620 vec![
2621 self.expr
2622 .clone()
2623 .call_unary(UnaryFunc::RecordGet(scalar_func::RecordGet(0))),
2624 ],
2625 ),
2626
2627 // JsonbAgg takes _anything_ as input, but must output a Jsonb object.
2628 AggregateFunc::JsonbObjectAgg { .. } => {

Callers 2

on_unique_window_aggMethod · 0.80
actionMethod · 0.80

Calls 15

CastInt64ToNumericClass · 0.85
CastUint64ToNumericClass · 0.85
RecordGetClass · 0.85
enumerateMethod · 0.80
if_then_elseMethod · 0.45
call_unaryMethod · 0.45
cloneMethod · 0.45
collectMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected