Allocating Intermediate Aggregate Storage | Teradata Vantage - Allocating Storage - 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_INIT aggregation phase, a UDF must allocate the intermediate storage pointed to by FNC_Context_t.interim1.

To allocate the required memory, the UDF calls the FNC_DefMem library function, specifying the size of the structure, which has a 64000 byte maximum. The UDF cannot request more memory than the value of interim_size in the CLASS AGGREGATE clause of the CREATE FUNCTION statement. If interim_size is omitted, then the limit is 64 bytes.

For best performance, allocate only enough memory to satisfy the needs of the function for intermediate storage.

In the standard deviation function example, the size of the structure can be computed by using sizeof(AGR_Storage). The following statement allocates the intermediate storage pointed to by FNC_Context_t.interim1:

s1 = FNC_DefMem(sizeof(AGR_Storage));
FNC_DefMem returns a NULL pointer for any of the following conditions:
  • The aggregate function asks for more memory than the value of interim_size in the CLASS AGGREGATE clause of the CREATE FUNCTION statement
  • The CLASS AGGREGATE clause of the CREATE FUNCTION statement does not specify a value for interim_size and the aggregate function asks for more than the default 64 bytes
  • The function asks for more than the 64000 byte maximum

If the UDF cannot complete without the memory, then the function can return an error by setting up the SQLSTATE error results argument.