Example Using FNC_SetNullBitVectorByElemIndex - 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ā„¢

In this example, memset() is called to initialize a new NullBitVector by setting all bytes to 0 after it has been allocated by the caller for an ARRAY of type phonenumbers_ary. The required information for these operations is retrieved by calling FNC_GetArrayTypeInfo. Then, FNC_SetNullBitVectorByElemIndex is called to set one of the bits to "not present".

The following example is based on the following 2-D ARRAY definition:

/* Oracle-compatible and Teradata syntax respectively: */
CREATE TYPE myArray AS VARRAY(1:20)(1:20) OF INTEGER;
CREATE TYPE myArray AS INTEGER ARRAY[1:20][1:20];

void ArrayUDF ( ARRAY_HANDLE  *a,
                char           sqlstate[6])
{
    NullBitVecType *NullBitVector;
    array_info_t arrayInfo;
    long nullVecBufSize;
    int aryIndex[FNC_ARRAYMAXDIMENSIONS];
    bounds_t arrayScope[FNC_ARRAYMAXDIMENSIONS];

    /* Call FNC_GetArrayTypeInfo first to find out the number of */
    /* elements in the array. */
    FNC_GetArrayTypeInfo(*a,
                         &arrayInfo,
                         arrayScope);
    (arrayInfo.totalNumElements % 8 == 0) ?
       (nullVecBufSize = arrayInfo.totalNumElements / 8) :
       (nullVecBufSize = arrayInfo.totalNumElements / 8) + 1;

    /* Allocate a new NullBitVector array. */
    NullBitVector = (NullBitVecType*)FNC_malloc(nullVecBufSize);

    /* Initialize the NullBitVector to default values */
    memset(NullBitVector, 0, nullVecBufSize);

    /* Set one bit in NullBitVector to 1 (present) */
    aryIndex[0] = 1;
    aryIndex[1] = 1;
    FNC_SetNullBitVectorByElemIndex(NullBitVector, aryIndex, 1,
       nullVecBufSize, arrayScope, arrayInfo.numDimensions);
    ...
}