From 3460da9f54a47e695e784430fd310308d3f277e3 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Sun, 22 May 2022 15:34:33 +0800 Subject: [PATCH] fix(query): stddev desc order and bsearch support desc search --- src/query/src/qAggMain.c | 13 ++++++++++++- src/query/src/qFill.c | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 5701f95f00..42e649be10 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -1856,6 +1856,17 @@ int32_t tsCompare(const void* p1, const void* p2) { } } +int32_t tsCompareDesc(const void* p1, const void* p2) { + TSKEY k = *(TSKEY*)p1; + SResPair* pair = (SResPair*)p2; + + if (k == pair->key) { + return 0; + } else { + return k > pair->key? -1:1; + } +} + static void stddev_dst_function(SQLFunctionCtx *pCtx) { SStddevdstInfo *pStd = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); @@ -1877,7 +1888,7 @@ static void stddev_dst_function(SQLFunctionCtx *pCtx) { SResPair* p = taosArrayGet(resList, 0); avg = p->avg; } else { // todo opt performance by using iterator since the timestamp lsit is matched with the output result - SResPair* p = bsearch(&pCtx->startTs, resList->pData, len, sizeof(SResPair), tsCompare); + SResPair* p = bsearch(&pCtx->startTs, resList->pData, len, sizeof(SResPair), pCtx->order == TSDB_ORDER_DESC ? tsCompareDesc : tsCompare); if (p == NULL) { return; } diff --git a/src/query/src/qFill.c b/src/query/src/qFill.c index 48ca064d87..d83620c78f 100644 --- a/src/query/src/qFill.c +++ b/src/query/src/qFill.c @@ -464,8 +464,8 @@ void taosFillSetInputDataBlock(SFillInfo* pFillInfo, const SSDataBlock* pInput) pFillInfo->interval.slidingUnit, pFillInfo->precision); numOfRes += 1; - if(numOfRes < numOfRows) { - // reset current Key + if(numOfRes < numOfRows || pFillInfo->currentKey < lastKey) { + // set currentKey max pFillInfo->currentKey = tsList[0]; } } -- GitLab