Combining Intermediate Storage Areas - Advanced SQL Engine - Teradata Database

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-24
dita:mapPath
qwr1571437338192.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1147
lifecycle
previous
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.