Combining Intermediate Aggregate Storage Areas | Teradata Vantage - Combining Intermediate Storage Areas - Analytics Database - Teradata Vantage

SQL External Routine Programming

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2023-07-11
dita:mapPath
iiv1628111441820.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
B035-1147
lifecycle
latest
Product Category
Teradata Vantageā„¢

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;
The AGR_COMBINE aggregation phase is not applicable for window aggregate functions.