Example Using FNC_LobLoc2Ref - 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™
#define BUFFER_SIZE 500

/* Aggregate intermediate record */
typedef struct
{
   FNC_LobLength_t length;
   LOB_REF         ref;
   BYTE            prefix[BUFFER_SIZE];
} intrec_t;
void Max_Blob(FNC_Phase          phase,
              FNC_Context_t      *fctx,
              LOB_LOCATOR        *x,
              LOB_RESULT_LOCATOR *result,
              int                *x_i,
              int                *result_i,
              char               sqlstate[6])
{
   intrec_t        *s1 = (intrec_t*) fctx->interim1;
   LOB_CONTEXT_ID  id;
   FNC_LobLength_t actsize;

   switch (phase)
   {
   case AGR_INIT:
      s1 = (intrec_t *)FNC_DefMem(sizeof(intrec_t));
      s1->length = FNC_GetLobLength(*x);
      FNC_LobOpen(*x, &id, 0, BUFFER_SIZE);
      FNC_LobRead(id, s1->prefix, BUFFER_SIZE, &actsize);
      FNC_LobClose(id);

      /* if the object length is less than the size
         allotted, pad the remaining bytes with zeros. */
      while (actsize < BUFFER_SIZE)
         s1->prefix[actsize++] = 0;
       FNC_LobLoc2Ref(*x, &s1->ref); 

   case AGR_DETAIL:

      ...

      break;

   ...

}

For a complete example that uses FNC_LobLoc2Ref, see C Aggregate Function Using LOBs.