16.20 - Combining Intermediate Storage Areas - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
16.20
Release Date
April 2020
Content Type
Programming Reference
Publication ID
B035-1147-162K
Language
English (United States)

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.