diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 726e0eba6bcc1d748ed7d5f0796a4124ee7f0505..c51eff6a48b55efd6fe090f22473cf642b304696 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -38,9 +38,9 @@ typedef struct STagVal STagVal; typedef struct STag STag; typedef struct SColData SColData; -#define HAS_NONE ((int8_t)0x1) -#define HAS_NULL ((int8_t)0x2) -#define HAS_VALUE ((int8_t)0x4) +#define HAS_NONE ((uint8_t)0x1) +#define HAS_NULL ((uint8_t)0x2) +#define HAS_VALUE ((uint8_t)0x4) // bitmap ================================ const static uint8_t BIT2_MAP[4][4] = {{0b00000000, 0b00000001, 0b00000010, 0}, diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index ee68e53e1857a51ba90d28ee61e43b38ab99bd9a..6affa2bf50a25b9016a2d5eef398d95964d65a39 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -1239,87 +1239,218 @@ _exit: static FORCE_INLINE int32_t tColDataAppendValue1(SColData *pColData, SColVal *pColVal) { // HAS_NONE int32_t code = 0; - if (pColVal->isNone) { - } else if (pColVal->isNull) { - pColData->flag |= HAS_NULL; - // TODO - } else { - pColData->flag |= HAS_VALUE; - // TODO + if (!pColVal->isNone) { + code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1)); + if (code) goto _exit; + + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + SET_BIT1(pColData->pBitMap, iVal, 0); + } + SET_BIT1(pColData->pBitMap, pColData->nVal, 1); + + if (pColVal->isNull) { + pColData->flag |= HAS_NULL; + } else { + pColData->flag |= HAS_VALUE; + code = tColDataPutValue(pColData, pColVal); + if (code) goto _exit; + } } pColData->nVal++; +_exit: return code; } static FORCE_INLINE int32_t tColDataAppendValue2(SColData *pColData, SColVal *pColVal) { // HAS_NULL int32_t code = 0; - if (pColVal->isNone) { - pColData->flag |= HAS_NONE; - // TODO - } else if (pColVal->isNull) { - } else { - pColData->flag |= HAS_VALUE; - // TODO + if (!pColVal->isNull) { + code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1)); + if (code) goto _exit; + + if (pColVal->isNone) { + pColData->flag |= HAS_NONE; + + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + SET_BIT1(pColData->pBitMap, iVal, 1); + } + SET_BIT1(pColData->pBitMap, pColData->nVal, 0); + } else { + pColData->flag |= HAS_VALUE; + + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + SET_BIT1(pColData->pBitMap, iVal, 0); + } + SET_BIT1(pColData->pBitMap, pColData->nVal, 1); + + code = tColDataPutValue(pColData, pColVal); + if (code) goto _exit; + } } pColData->nVal++; +_exit: return code; } -static FORCE_INLINE int32_t tColDataAppendValue3(SColData *pColData, SColVal *pColVal) { // HAS_NONE | HAS_NULL +static FORCE_INLINE int32_t tColDataAppendValue3(SColData *pColData, SColVal *pColVal) { // HAS_NULL|HAS_NONE int32_t code = 0; if (pColVal->isNone) { + code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1)); + if (code) goto _exit; + + SET_BIT1(pColData->pBitMap, pColData->nVal, 0); } else if (pColVal->isNull) { + code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1)); + if (code) goto _exit; + + SET_BIT1(pColData->pBitMap, pColData->nVal, 1); } else { + uint8_t *pBitMap = NULL; + code = tRealloc(&pBitMap, BIT2_SIZE(pColData->nVal + 1)); + if (code) goto _exit; + + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + SET_BIT2(pBitMap, iVal, GET_BIT1(pColData->pBitMap, iVal)); + } + SET_BIT2(pBitMap, pColData->nVal, 2); + + pColData->flag |= HAS_VALUE; + + tFree(pColData->pBitMap); + pColData->pBitMap = pBitMap; + + code = tColDataPutValue(pColData, pColVal); + if (code) goto _exit; } pColData->nVal++; +_exit: return code; } static FORCE_INLINE int32_t tColDataAppendValue4(SColData *pColData, SColVal *pColVal) { // HAS_VALUE int32_t code = 0; if (pColVal->isNone) { + pColData->flag |= HAS_NONE; + + code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1)); + if (code) goto _exit; + + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + SET_BIT1(pColData->pBitMap, iVal, 1); + } + SET_BIT1(pColData->pBitMap, pColData->nVal, 0); } else if (pColVal->isNull) { + pColData->flag |= HAS_NULL; + + code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1)); + if (code) goto _exit; + + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + SET_BIT1(pColData->pBitMap, iVal, 1); + } + SET_BIT1(pColData->pBitMap, pColData->nVal, 0); } else { + code = tColDataPutValue(pColData, pColVal); + if (code) goto _exit; } pColData->nVal++; +_exit: return code; } -static FORCE_INLINE int32_t tColDataAppendValue5(SColData *pColData, SColVal *pColVal) { // HAS_VALUE | HAS_NONE +static FORCE_INLINE int32_t tColDataAppendValue5(SColData *pColData, SColVal *pColVal) { // HAS_VALUE|HAS_NONE int32_t code = 0; - if (pColVal->isNone) { - } else if (pColVal->isNull) { + if (pColVal->isNull) { + pColData->flag |= HAS_NULL; + + uint8_t *pBitMap = NULL; + code = tRealloc(&pBitMap, BIT2_SIZE(pColData->nVal + 1)); + if (code) goto _exit; + + for (int32_t iVal = 0; iVal < pColData->nData; iVal++) { + SET_BIT2(pBitMap, iVal, GET_BIT1(pColData->pBitMap, iVal) ? 2 : 0); + } + SET_BIT2(pBitMap, pColData->nVal, 1); + + tFree(pColData->pBitMap); + pColData->pBitMap = pBitMap; } else { + code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1)); + if (code) goto _exit; + + if (pColVal->isNone) { + SET_BIT1(pColData->pBitMap, pColData->nVal, 0); + } else { + SET_BIT1(pColData->pBitMap, pColData->nVal, 1); + + code = tColDataPutValue(pColData, pColVal); + if (code) goto _exit; + } } + pColData->nVal++; +_exit: return code; } -static FORCE_INLINE int32_t tColDataAppendValue6(SColData *pColData, SColVal *pColVal) { // HAS_VALUE | HAS_NULL +static FORCE_INLINE int32_t tColDataAppendValue6(SColData *pColData, SColVal *pColVal) { // HAS_VALUE|HAS_NULL int32_t code = 0; if (pColVal->isNone) { - } else if (pColVal->isNull) { + pColData->flag |= HAS_NONE; + + uint8_t *pBitMap = NULL; + code = tRealloc(&pBitMap, BIT2_SIZE(pColData->nVal + 1)); + if (code) goto _exit; + + for (int32_t iVal = 0; iVal < pColData->nData; iVal++) { + SET_BIT2(pBitMap, iVal, GET_BIT1(pColData->pBitMap, iVal) ? 2 : 1); + } + SET_BIT2(pBitMap, pColData->nVal, 0); + + tFree(pColData->pBitMap); + pColData->pBitMap = pBitMap; } else { + code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1)); + if (code) goto _exit; + + if (pColVal->isNull) { + SET_BIT1(pColData->pBitMap, pColData->nVal, 0); + } else { + SET_BIT1(pColData->pBitMap, pColData->nVal, 1); + + code = tColDataPutValue(pColData, pColVal); + if (code) goto _exit; + } } pColData->nVal++; +_exit: return code; } static FORCE_INLINE int32_t tColDataAppendValue7(SColData *pColData, - SColVal *pColVal) { // HAS_VALUE | HAS_NULL | HAS_NONE + SColVal *pColVal) { // HAS_VALUE|HAS_NULL|HAS_NONE int32_t code = 0; + code = tRealloc(&pColData->pBitMap, BIT2_SIZE(pColData->nVal + 1)); + if (code) goto _exit; + if (pColVal->isNone) { + SET_BIT2(pColData->pBitMap, pColData->nVal, 0); } else if (pColVal->isNull) { + SET_BIT2(pColData->pBitMap, pColData->nVal, 1); } else { + SET_BIT2(pColData->pBitMap, pColData->nVal, 2); + + code = tColDataPutValue(pColData, pColVal); + if (code) goto _exit; } pColData->nVal++; +_exit: return code; } static int32_t (*tColDataAppendValueImpl[])(SColData *pColData, SColVal *pColVal) = { @@ -1332,7 +1463,6 @@ static int32_t (*tColDataAppendValueImpl[])(SColData *pColData, SColVal *pColVal tColDataAppendValue6, // HAS_VALUE | HAS_NULL tColDataAppendValue7 // HAS_VALUE | HAS_NULL | HAS_NONE }; - int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal) { int32_t code = 0;