From 7e3290879ce23acf5db139e82f6e22de88cb0ee5 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 25 Nov 2022 17:27:04 +0800 Subject: [PATCH] more api --- include/common/tdataformat.h | 4 ++ source/common/src/tdataformat.c | 68 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 057cff7624..9e3b9d191c 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -118,6 +118,10 @@ uint8_t tColDataGetBitValue(const SColData *pColData, int32_t iVal); int32_t tColDataCopy(SColData *pColDataSrc, SColData *pColDataDest); extern void (*tColDataCalcSMA[])(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, int16_t *numOfNull); +// for stmt bind +int32_t tColDataAddValueByBind(SColData *pColData, TAOS_MULTI_BIND *pBind); +int32_t tColDataSortMerge(SColData *aColData); + // STRUCT ================================ struct STColumn { col_id_t colId; diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index f1ccef586e..55d843f616 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -1660,6 +1660,74 @@ _exit: return code; } +int32_t tColDataAddValueByBind(SColData *pColData, TAOS_MULTI_BIND *pBind) { + int32_t code = 0; + + bool allValue; + bool allNull; + if (pBind->is_null) { + bool same = (memcmp(pBind->is_null, pBind->is_null + 1, pBind->num - 1) == 0); + allNull = (same && pBind->is_null[0] != 0); + allValue = (same && pBind->is_null[0] == 0); + } else { + allNull = false; + allValue = true; + } + + pColData->nVal += pBind->num; + if (IS_VAR_DATA_TYPE(pBind->buffer_type)) { + // var + for (int32_t i = 0; i < pBind->num; ++i) { + if (pBind->is_null[i]) { + // tColDataAppendNull(pColData); + } else { + uint8_t *pData = (uint8_t *)pBind->buffer + pBind->buffer_length * i; + + SValue value = {.nData = pBind->length[i], .pData = pData}; + } + } + } else { + // fix + pColData->nVal += pBind->num; + + if (allValue) { + pColData->flag |= HAS_VALUE; + if (pColData->flag != HAS_VALUE) { + // todo + } + + int32_t nData = pColData->nData + TYPE_BYTES[pBind->buffer_type] * pBind->num; + code = tRealloc(&pColData->pData, nData); + if (code) goto _exit; + + memcpy(pColData->pData + pColData->nData, pBind->buffer, nData - pColData->nData); + pColData->nData = nData; + } else if (allNull) { + pColData->flag |= HAS_NULL; + + // todo + + } else { + for (int32_t i = 0; i < pBind->num; ++i) { + if (pBind->is_null[i]) { + code = tColDataAppendValue(pColData, &COL_VAL_NULL(pColData->cid, pColData->type)); + // tColDataAppendNull(pColData); + } else { + uint8_t *pData = (uint8_t *)pBind->buffer + TYPE_BYTES[pBind->buffer_type] * i; + } + } + } + } + +_exit: + return code; +} + +int32_t tColDataSortMerge(SColData *aColData) { + // todo + return 0; +} + #define CALC_SUM_MAX_MIN(SUM, MAX, MIN, VAL) \ do { \ (SUM) += (VAL); \ -- GitLab