During the AGR_COMBINE aggregation phase, a UDF must combine two intermediate aggregate storage areas into one storage area for each group that is being aggregated. The storage areas that the function is combining are the results from different AMPs for a specific group.
The storage areas are pointed to by interim1 and interim2 in the FNC_Context_t function context structure parameter. The pointer in interim2 points to the aggregate storage area to combine with the aggregate storage area specified by interim1.
The ultimate result is to create one summary aggregate storage area for each group on which the aggregate function operates.
In the standard deviation example, the function can define another pointer to AGR_Storage that points to the FNC_Context_t.interim2 function argument. If the argument name is fctx, the following statement defines a pointer to AGR_Storage named s2:
AGR_Storage *s2 = fctx->interim2;
The following statements combine the aggregate storage areas:
s1->n += s2->n; s1->x_sq += s2->x_sq; s1->x_sum += s2->x_sum;