17.00 - 17.05 - FNC_CheckNullBitVectorByElemIndexの使用例 - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL外部ルーチン プログラミング

Product
Advanced SQL Engine
Teradata Database
Release Number
17.00
17.05
Published
2020年6月
Content Type
プログラミング リファレンス
Publication ID
B035-1147-170K-JPN
Language
日本語 (日本)

この例では、FNC_GetArrayElementsを呼び出した後で、FNC_CheckNullBitVectorByElemIndexを呼び出して、phonenumbers_ary型のARRAYに対応するNullBitVectorの構成要素1の値を検査しています。

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);
    ...
}