Example Using FNC_LobRef2Loc - 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 10000

/* Aggregate intermediate record */
typedef struct
{
   FNC_LobLength_t length;
   LOB_REF         ref;
   BYTE            prefix[500];
} 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 actlen;

   switch (phase)
   {
   case AGR_INIT:

      ...

   case AGR_DETAIL:

      ...

      break;
   case AGR_FINAL:
      FNC_LobOpen(*(FNC_LobRef2Loc(&s1->ref)), &id, 0, 0); 
      FNC_LobRead(id, buffer, BUFFER_SIZE, &actlen);
      FNC_LobAppend(*result, buffer, actlen, &actlen);
      FNC_LobClose(id);
      break;

   ...

}

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