From 4eaf1f5bb655e99d739ef2ce58b51e445d322682 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 12 May 2022 17:34:07 +0800 Subject: [PATCH] refactor: do some internal refactor. --- source/libs/function/src/builtinsimpl.c | 28 ++++++++++++------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 4d594372db..be6eb59f17 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -1641,7 +1641,7 @@ int32_t percentileFunction(SqlFunctionCtx* pCtx) { pResInfo->complete = true; return 0; } else { - pInfo->pMemBucket = tMemBucketCreate(pCtx->inputBytes, pCtx->inputType, pInfo->minval, pInfo->maxval); + pInfo->pMemBucket = tMemBucketCreate(pCol->info.bytes, type, pInfo->minval, pInfo->maxval); } } @@ -1692,30 +1692,28 @@ int32_t percentileFunction(SqlFunctionCtx* pCtx) { pInfo->numOfElems += 1; } } + } else { + // the second stage, calculate the true percentile value + int32_t start = pInput->startRowIndex; + for (int32_t i = start; i < pInput->numOfRows + start; ++i) { + if (colDataIsNull_f(pCol->nullbitmap, i)) { + continue; + } - return 0; - } - - // the second stage, calculate the true percentile value - int32_t start = pInput->startRowIndex; - for (int32_t i = start; i < pInput->numOfRows + start; ++i) { - if (colDataIsNull_f(pCol->nullbitmap, i)) { - continue; + char* data = colDataGetData(pCol, i); + notNullElems += 1; + tMemBucketPut(pInfo->pMemBucket, data, 1); } - char* data = colDataGetData(pCol, i); - - notNullElems += 1; - tMemBucketPut(pInfo->pMemBucket, data, 1); + SET_VAL(pResInfo, notNullElems, 1); } - SET_VAL(pResInfo, notNullElems, 1); return TSDB_CODE_SUCCESS; } int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SVariant* pVal = &pCtx->param[1].param; - double v = pVal->nType == TSDB_DATA_TYPE_INT ? pVal->i : pVal->d; + double v = (pVal->nType == TSDB_DATA_TYPE_BIGINT) ? pVal->i : pVal->d; SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); SPercentileInfo* ppInfo = (SPercentileInfo*)GET_ROWCELL_INTERBUF(pResInfo); -- GitLab