16.20 - Classes that Hold the Data to Retain Between Iterations - 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)

To enable Tbl.allocCtx() to serialize a class object into a binary stream and allocate storage for it, the class that the Java table UDF uses to hold the intermediate data must implement the java.io.Serializable interface. (The class must be serializable.) The size of the serialized binary stream determines the size of the allocated intermediate storage and it should be big enough to hold all the data of the object.

In Java, a serializable class overwrites the default methods writeObject(java.io.ObjectOutputStream out) and readObject(java.io.ObjectInputStream in) with its own customized implementation. An object of such a class automatically calls writeObject() during its serialization and readObject() during its deserialization.

If the object that the Java table UDF uses to hold intermediate data has object type fields, the UDF must initialize those fields to non-null values before calling Tbl.allocCtx(). One way to do this is to implement the writeObject() method to check the fields for nulls and initialize them if needed.

Similarly, if the object has array type fields, the UDF must initialize the array itself and each element of the array to non-null values before calling Tbl.allocCtx().