17.10 - Example - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1147-171K
Language
English (United States)

In this example, FNC_CheckNullBitVectorByElemIndex is called to check the value of element 1 of the NullBitVector, which corresponds to an ARRAY of type phonenumbers_ary, after calling FNC_GetArrayElements.

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

    /* Call FNC_GetArrayTypeInfo first to find out the number of */
    /* elements in the array. */
    FNC_GetArrayTypeInfo(*ary_handle,
                         &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);
    arrayRange =
    (bounds_t*)FNC_malloc(sizeof(bounds_t)*arrayInfo.numDimensions);

    /* Set values of arrayRange to correspond to the range [1:2][1:2] */
    arrayRange[0].lowerBound = 1;
    arrayRange[0].upperBound = 2;
    arrayRange[1].lowerBound = 1;
    arrayRange[1].upperBound = 2;

    /* Get elements within the range [1:2][1:2] of myArray. */
    FNC_GetArrayElements(*ary_handle, arrayRange, &result, buffer,
       NullBitVector, &length);

    /* Check the presence bit for element 1 of phonenumbers_ary. */
    arrayIndex[0] = 1;
    presenceBit = FNC_CheckNullBitVectorByElemIndex(NullBitVector,
       arrayIndex, nullVecBufSize, arrayScope, arrayInfo.numDimensions);
    ...
}