Combining Intermediate Storage Areas - Advanced SQL Engine - Teradata Database

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-27
dita:mapPath
rin1593638965306.ditamap
dita:ditavalPath
rin1593638965306.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.