diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 2beb53a312166dd7f0fa054f82be4c8ccffaefda..4a0b2682cbb6fbd5a1573db2f52f179adf27725d 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 04472c42ec49093987859efcd4a900ba9e22dddd..d4a362659c9f50eb28edb190597b79c6ea4b2fb3 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);