diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index e8830e32f8..82cbbcf6a4 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -122,7 +122,7 @@ extern void (*tColDataCalcSMA[])(SColData *pColData, int64_t *sum, int64_t *max, // for stmt bind int32_t tColDataAddValueByBind(SColData *pColData, TAOS_MULTI_BIND *pBind); -int32_t tColDataSortMerge(SColData *aColData); +void tColDataSortMerge(SArray *colDataArr); // for encode/decode int32_t tPutColData(uint8_t *pBuf, SColData *pColData); diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 218c8e5682..b5946a5847 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -2106,9 +2106,45 @@ _exit: return code; } -int32_t tColDataSortMerge(SColData *aColData) { - // todo - return 0; +void tColDataSortMerge(SArray *colDataArr) { + int32_t nColData = TARRAY_SIZE(colDataArr); + SColData *aColData = (SColData *)TARRAY_DATA(colDataArr); + + if (aColData[0].nVal <= 1) goto _exit; + + ASSERT(aColData[0].type == TSDB_DATA_TYPE_TIMESTAMP); + ASSERT(aColData[0].cid == PRIMARYKEY_TIMESTAMP_COL_ID); + ASSERT(aColData[0].flag == HAS_VALUE); + + int8_t doSort = 0; + int8_t doMerge = 0; + // scan ------- + TSKEY *aKey = (TSKEY *)aColData[0].pData; + for (int32_t iVal = 1; iVal < aColData[0].nVal; ++iVal) { + if (aKey[iVal] > aKey[iVal - 1]) { + continue; + } else if (aKey[iVal] < aKey[iVal - 1]) { + doSort = 1; + break; + } else { + doMerge = 1; + } + } + + // sort ------- + if (doSort) { + ASSERT(0); + // todo + } + + // merge ------- + if (doMerge) { + ASSERT(0); + // todo + } + +_exit: + return; } int32_t tPutColData(uint8_t *pBuf, SColData *pColData) {