MCPcopy Create free account
hub / github.com/apache/cloudberry / makeNumericAggState

Function makeNumericAggState

src/backend/utils/adt/numeric.c:4624–4645  ·  view source on GitHub ↗

* Prepare state data for a numeric aggregate function that needs to compute * sum, count and optionally sum of squares of the input. */

Source from the content-addressed store, hash-verified

4622 * sum, count and optionally sum of squares of the input.
4623 */
4624static NumericAggState *
4625makeNumericAggState(FunctionCallInfo fcinfo, bool calcSumX2)
4626{
4627 NumericAggState *state;
4628 MemoryContext agg_context;
4629 MemoryContext old_context;
4630
4631 if (!AggCheckCallContext(fcinfo, &agg_context))
4632 elog(ERROR, "aggregate function called in non-aggregate context");
4633
4634 old_context = MemoryContextSwitchTo(agg_context);
4635
4636 state = (NumericAggState *) palloc0(sizeof(NumericAggState));
4637 state->calcSumX2 = calcSumX2;
4638 state->agg_context = agg_context;
4639 init_sumaccum(&state->sumX);
4640 init_sumaccum(&state->sumX2);
4641
4642 MemoryContextSwitchTo(old_context);
4643
4644 return state;
4645}
4646
4647/*
4648 * Like makeNumericAggState(), but allocate the state in the current memory

Callers 3

numeric_accumFunction · 0.85
numeric_avg_accumFunction · 0.85
int8_accumFunction · 0.85

Calls 3

AggCheckCallContextFunction · 0.85
MemoryContextSwitchToFunction · 0.85
palloc0Function · 0.50

Tested by

no test coverage detected