Allocating Intermediate Aggregate Storage | Teradata Vantage - Allocating Storage - Analytics Database - Teradata Vantage

SQL External Routine Programming

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2023-07-11
dita:mapPath
iiv1628111441820.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
B035-1147
lifecycle
latest
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.