Saving Intermediate Aggregate Storage Results | Teradata Vantage - Saving Intermediate Results - 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_INIT aggregation phase, a UDF must also save the first set of data values passed in through arguments into the intermediate aggregate storage area. The first set of data values are for the first row to aggregate for the group.

Thereafter, each time the function is called during the AGR_DETAIL aggregation phase, it must accumulate the row data passed in through arguments into the intermediate aggregate storage area for the specific group. Each group being aggregated to has a separate intermediate storage area.

The aggregation storage area is pointed to by interim1 in the FNC_Context_t function context argument.

In the standard deviation example, the x input argument is the column the standard deviation is being calculated for. For the standard deviation calculation, the function uses the value of x to calculate the following:
  • sum(X 2)
  • sum(X)

The following statements perform the necessary calculations using the column value, and then combine the results with the intermediate storage:

s1->n++;
s1->x_sq  += *x * *x;
s1->x_sum += *x;