Example: FNC_TblOpGetBaseInfo - 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ā„¢

The following shows how FNC_TblOpGetBaseInfo can be used in a contract function.

int tblopudt_metain_contract(
                    INTEGER *Result,
                    int *indicator_Result,
                    char sqlstate[6],
                    SQL_TEXT extname[129],
                    SQL_TEXT specific_name[129],
                    SQL_TEXT error_message[257])
{
    FNC_TblOpColumnDef_t    *oCols;
    FNC_TblOpColumnDef_t    *iCols;
    UDT_BaseInfo_t *udtBaseInfo;
    Stream_Fmt_en   format;
    InputInfo_t *icolinfo;
    int incount, outcount , ocolcount;
    int i,j, totalcols;
    char mycontract[] = "this is my contract... this is my contract... this is my contract...";
    char msg[500] = "";

    FNC_TblOpGetStreamCount(&incount, &outcount);
    if(incount == 0)
    {
     SetError("U0003", "mift1 requires number of input streams to be > 0.");
     return -1;
    }

    icolinfo = FNC_malloc (incount * sizeof(InputInfo_t));

    totalcols = 0;
    for(i=0; i < incount; i++)
    {
      icolinfo[i].colcount = FNC_TblOpGetColCount(i, ISINPUT);
      totalcols += icolinfo[i].colcount;

      icolinfo[i].iCols = FNC_malloc(TblOpSIZECOLDEF(icolinfo[i].colcount));
      TblOpINITCOLDEF(icolinfo[i].iCols, icolinfo[i].colcount);
      FNC_TblOpGetColDef(i, ISINPUT, icolinfo[i].iCols);

       /* Retreive UDT metadata info for each column and write to trace table */
       iCols = icolinfo[i].iCols;
       icolinfo[i].baseColInfo = FNC_malloc(sizeof(UDT_BaseInfo_t) * iCols->num_columns);
       FNC_TblOpGetBaseInfo(iCols,icolinfo[i].baseColInfo);      
       
    }

    /* Allocate space for columns. */
    oCols = (FNC_TblOpColumnDef_t *)FNC_malloc( TblOpSIZECOLDEF(totalcols) );
    memset(oCols, 0 , TblOpSIZECOLDEF(totalcols) );
    oCols->num_columns = totalcols;
    oCols->length = TblOpSIZECOLDEF(totalcols) - (2 * sizeof(int)) ;
    TblOpINITCOLDEF(oCols, totalcols);
    ocolcount = 0;

    /* Copy input columns to output columns. */
     for(j=0; j < incount; j++)
     {
       iCols = icolinfo[j].iCols;
       for(i=0;i < iCols->num_columns;i++)
       {
         oCols->column_types[ocolcount].datatype = VARCHAR_DT;
         oCols->column_types[ocolcount].charset = LATIN_CT;
         oCols->column_types[ocolcount].size.length = 32;
         ocolcount++;
      }
    }

    FNC_TblOpSetContractDef(mycontract, strlen(mycontract)+1);
    /* Define output columns. */
    FNC_TblOpSetOutputColDef(0, oCols);
    format = INDICFMT1;
    FNC_TblOpSetFormat("RECFMT", 0, ISINPUT, &format, sizeof(format));
    FNC_TblOpSetFormat("RECFMT", 0, ISOUTPUT, &format, sizeof(format));
    FNC_free(oCols);
    for(i=0; i < incount; i++)
    {
      FNC_free(icolinfo[i].iCols);
      FNC_free(icolinfo[i].baseColInfo);
    }

    FNC_free(icolinfo);
    *Result = 1;
}