Producing the Final Group Result - 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_FINAL aggregation phase, a UDF produces the final result for the group. The function must set the result argument to the final value.

The storage area pointed to by interim1 in the FNC_Context_t argument points to the aggregate storage area for the group. The function uses the interim1 pointer to calculate the final value and return it in the result argument.

In the standard deviation example, the function can use the following statements to calculate the final value:

FLOAT term2    = s1->x_sum / s1->n;
FLOAT variance = (s1->x_sq / s1->n) - (term2 * term2);

The following statement sets the result argument to the final value of the standard deviation:

*result = sqrt(variance);