Clob and Blob Classes - 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
ft:locale
en-US
ft:lastEdition
2025-03-30
dita:mapPath
iiv1628111441820.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
qnu1472247494689
lifecycle
latest
Product Category
Teradata Vantageā„¢

Teradata implements java.sql.Clob and java.sql.Blob as serializable classes. Thus, a table function can use them, passing their objects between iterations of table function execution.

However, writing a table UDF involves special considerations when the table UDF uses Clob or Blob objects to hold the data in the intermediate storage.

Consider a table UDF that retains data between iterations using an item_clob object:

class item_clob implements Serializable
{
   int id;
   java.sql.Clob myclob;

   ...
}

To ensure that Tbl.allocCtx() allocates intermediate storage space big enough to hold all the data of the object for all iterations of the table function, the table UDF can implement the writeObject() method to write a dummy byte array into the serialized binary stream if member myclob is null.

The size of the dummy byte array is 64, which is the size of a fully serialized Teradata java.sql.Clob and java.sql.Blob object.

class item_clob implements Serializable
{
   int id;
   java.sql.Clob myclob;

   private void writeObject(java.io.ObjectOutputStream out)
   throws IOException
   {
      byte[] dummy = new byte[64];
      out.defaultWriteObject();
      /* Allocate storage for lob by writing the dummy bytes  */
      /* into its serialized binary stream if myclob is null. */
      if (myclob == null)
         out.write(dummy);
   }

   private void readObject(java.io.ObjectInputStream in)
   throws IOException, ClassNotFoundException
   {
      in.defaultReadObject();
   }
}

For a complete example, see Example: Table UDF Using Clob to Hold Data in Intermediate Storage.