TODO: codegen this function.
| 142 | |
| 143 | // TODO: codegen this function. |
| 144 | void Aggregator::InitAggSlots( |
| 145 | const vector<AggFnEvaluator*>& agg_fn_evals, Tuple* intermediate_tuple) { |
| 146 | vector<SlotDescriptor*>::const_iterator slot_desc = |
| 147 | intermediate_tuple_desc_->slots().begin() + GetNumGroupingExprs(); |
| 148 | for (int i = 0; i < agg_fn_evals.size(); ++i, ++slot_desc) { |
| 149 | // To minimize branching on the UpdateTuple path, initialize the result value so that |
| 150 | // the Add() UDA function can ignore the NULL bit of its destination value. E.g. for |
| 151 | // SUM(), if we initialize the destination value to 0 (with the NULL bit set), we can |
| 152 | // just start adding to the destination value (rather than repeatedly checking the |
| 153 | // destination NULL bit. The codegen'd version of UpdateSlot() exploits this to |
| 154 | // eliminate a branch per value. |
| 155 | // |
| 156 | // For boolean and numeric types, the default values are false/0, so the nullable |
| 157 | // aggregate functions SUM() and AVG() produce the correct result. For MIN()/MAX(), |
| 158 | // initialize the value to max/min possible value for the same effect. |
| 159 | AggFnEvaluator* eval = agg_fn_evals[i]; |
| 160 | eval->Init(intermediate_tuple); |
| 161 | |
| 162 | DCHECK(agg_fns_[i] == &(eval->agg_fn())); |
| 163 | const AggFn* agg_fn = agg_fns_[i]; |
| 164 | const AggFn::AggregationOp agg_op = agg_fn->agg_op(); |
| 165 | if ((agg_op == AggFn::MIN || agg_op == AggFn::MAX) |
| 166 | && !agg_fn->intermediate_type().IsStringType() |
| 167 | && !agg_fn->intermediate_type().IsTimestampType()) { |
| 168 | ExprValue default_value; |
| 169 | void* default_value_ptr = nullptr; |
| 170 | if (agg_op == AggFn::MIN) { |
| 171 | default_value_ptr = default_value.SetToMax((*slot_desc)->type()); |
| 172 | } else { |
| 173 | DCHECK_EQ(agg_op, AggFn::MAX); |
| 174 | default_value_ptr = default_value.SetToMin((*slot_desc)->type()); |
| 175 | } |
| 176 | RawValue::Write(default_value_ptr, intermediate_tuple, *slot_desc, nullptr); |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | void Aggregator::UpdateTuple( |
| 182 | AggFnEvaluator** agg_fn_evals, Tuple* tuple, TupleRow* row, bool is_merge) noexcept { |
nothing calls this directly
no test coverage detected