Defining What to Store in the Storage Area - 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ā„¢

The type of intermediate results that an aggregate UDF needs to save depends on the type of calculation that the UDF performs and whether the method wants to represent the intermediate results as a byte array or as an object.

Consider a standard deviation function STD_DEV(x) that uses the following equation:



Based on the calculation, the UDF needs to store the following:
  • N
  • sum(X 2)
  • sum(X)

Here is a Java class called agr_storage with fields that match the necessary intermediate values:

class agr_storage implements Serializable{
   double count;
   double x_sq;
   double x_sum;

   public agr_storage(double a, double b, double c){
      count = a;
      x_sq = b;
      x_sum = c;
   }
}

Alternatively, especially when better performance is required, the method that implements the aggregate UDF can use a ByteBuffer for the intermediate results and use the putDouble() and getDouble() methods on the ByteBuffer for the necessary intermediate values.