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 UDF is combining are the results from different AMPs for a specific group.

The ultimate result is to create one summary aggregate storage area for each group on which the aggregate UDF operates.

In the standard deviation example, the method can use another agr_storage instance for the data in the second intermediate aggregate storage area:

agr_storage s2 = (agr_storage)context[0].getObject(2);

The following statements combine the aggregate storage areas:

s1.count += s2.count;
s1.x_sq += s2.x_sq;
s1.x_sum += s2.x_sum;

Alternatively, if the method uses a byte array for the data in the intermediate aggregate storage area, the code looks like this:

ByteBuffer s2 = ByteBuffer.wrap(context[0].getBytes(2));
count += s2.getDouble();
x_sq += s2.getDouble();
x_sum += s2.getDouble();
The AGR_COMBINE aggregation phase is not applicable for window aggregate UDFs.