From 3a848ccb360ceae85ee5abe3511f6ddc56ffc4bd Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 11 Jan 2023 13:19:17 +0800 Subject: [PATCH] fix(query): fix the invalid return value check for percentile function. --- source/libs/function/src/builtinsimpl.c | 6 ++++-- source/libs/function/src/tpercentile.c | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 2beb53a312..4a0b2682cb 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -1662,6 +1662,8 @@ int32_t percentileFunction(SqlFunctionCtx* pCtx) { int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SVariant* pVal = &pCtx->param[1].param; + terrno = 0; + double v = 0; GET_TYPED_DATA(v, double, pVal->nType, &pVal->i); @@ -1675,8 +1677,8 @@ int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { tMemBucketDestroy(pMemBucket); - if (ppInfo->result < 0) { - return TSDB_CODE_NO_AVAIL_DISK; + if (terrno != TSDB_CODE_SUCCESS) { + return terrno; } return functionFinalize(pCtx, pBlock); diff --git a/source/libs/function/src/tpercentile.c b/source/libs/function/src/tpercentile.c index 04472c42ec..d4a362659c 100644 --- a/source/libs/function/src/tpercentile.c +++ b/source/libs/function/src/tpercentile.c @@ -92,6 +92,7 @@ static void resetPosInfo(SSlotInfo *pInfo) { double findOnlyResult(tMemBucket *pMemBucket) { ASSERT(pMemBucket->total == 1); + terrno = 0; for (int32_t i = 0; i < pMemBucket->numOfSlots; ++i) { tMemBucketSlot *pSlot = &pMemBucket->pSlots[i]; @@ -108,8 +109,10 @@ double findOnlyResult(tMemBucket *pMemBucket) { int32_t *pageId = taosArrayGet(list, 0); SFilePage *pPage = getBufPage(pMemBucket->pBuffer, *pageId); if (pPage == NULL) { - return -1; + terrno = TSDB_CODE_NO_AVAIL_DISK; + return 0; } + ASSERT(pPage->num == 1); double v = 0; @@ -546,9 +549,7 @@ double getPercentile(tMemBucket *pMemBucket, double percent) { // if only one elements exists, return it if (pMemBucket->total == 1) { - if (findOnlyResult(pMemBucket) < 0) { - return -1; - } + return findOnlyResult(pMemBucket); } percent = fabs(percent); -- GitLab