From 78dd9a035ec18c3625c9647313f9dc90087cabb9 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 13 Jun 2022 14:12:36 +0800 Subject: [PATCH] fix:to make time sort stable if timestamp is same in schemalsee --- source/client/src/clientSml.c | 40 +++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index bbf9eba363..aaa13ed266 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -1315,8 +1315,24 @@ static int32_t smlDealCols(SSmlTableInfo* oneTable, bool dataFormat, SArray *col void *p = taosArraySearch(oneTable->cols, &cols, smlKvTimeArrayCompare, TD_GE); if(p == NULL){ taosArrayPush(oneTable->cols, &cols); - }else{ - taosArrayInsert(oneTable->cols, TARRAY_ELEM_IDX(oneTable->cols, p), &cols); + }else{ // to make the sort stable for update data + SArray *sa = (SArray *)p; + SSmlKv *cur = (SSmlKv*)taosArrayGet(sa, 0); + SSmlKv *dCur = (SSmlKv*)taosArrayGet(cols, 0); + if(cur->i > dCur->i){ + taosArrayInsert(oneTable->cols, TARRAY_ELEM_IDX(oneTable->cols, p), &cols); + }else{ + ASSERT(cur->i == dCur->i); + int32_t index = TARRAY_ELEM_IDX(oneTable->cols, p) + 1; + for(; index < taosArrayGetSize(oneTable->cols); index++){ + SArray *tmp = (SArray *)taosArrayGet(oneTable->cols, index); + SSmlKv *curTs = (SSmlKv*)taosArrayGet(tmp, 0); + if(curTs->i > dCur->i){ + break; + } + } + taosArrayInsert(oneTable->cols, index, &cols); + } } return TSDB_CODE_SUCCESS; } @@ -1334,8 +1350,24 @@ static int32_t smlDealCols(SSmlTableInfo* oneTable, bool dataFormat, SArray *col void *p = taosArraySearch(oneTable->cols, &kvHash, smlKvTimeHashCompare, TD_GE); if(p == NULL){ taosArrayPush(oneTable->cols, &kvHash); - }else{ - taosArrayInsert(oneTable->cols, TARRAY_ELEM_IDX(oneTable->cols, p), &kvHash); + }else{ // to make the sort stable for update data + SHashObj *sa = (SHashObj *)p; + SSmlKv *cur = (SSmlKv *)taosHashGet(sa, TS, TS_LEN); + SSmlKv *dCur = (SSmlKv*)taosArrayGet(cols, 0); + if(cur->i > dCur->i){ + taosArrayInsert(oneTable->cols, TARRAY_ELEM_IDX(oneTable->cols, p), &cols); + }else{ + ASSERT(cur->i == dCur->i); + int32_t index = TARRAY_ELEM_IDX(oneTable->cols, p) + 1; + for(; index < taosArrayGetSize(oneTable->cols); index++){ + SHashObj *tmp = (SHashObj *)taosArrayGet(oneTable->cols, index); + SSmlKv *curTs = (SSmlKv *)taosHashGet(tmp, TS, TS_LEN); + if(curTs->i > dCur->i){ + break; + } + } + taosArrayInsert(oneTable->cols, index, &cols); + } } return TSDB_CODE_SUCCESS; } -- GitLab