[TD-2199]<fix>: fix bugs in percentile in case of no data in table.
This commit is contained in:
parent
7d22ca3fb9
commit
f91e989fd3
|
@ -2466,7 +2466,7 @@ static bool percentile_function_setup(SQLFunctionCtx *pCtx) {
|
||||||
static void percentile_function(SQLFunctionCtx *pCtx) {
|
static void percentile_function(SQLFunctionCtx *pCtx) {
|
||||||
int32_t notNullElems = 0;
|
int32_t notNullElems = 0;
|
||||||
|
|
||||||
SResultRowCellInfo * pResInfo = GET_RES_INFO(pCtx);
|
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||||
SPercentileInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
SPercentileInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||||
|
|
||||||
// the first stage, only acquire the min/max value
|
// the first stage, only acquire the min/max value
|
||||||
|
@ -2567,12 +2567,14 @@ static void percentile_finalizer(SQLFunctionCtx *pCtx) {
|
||||||
double v = pCtx->param[0].nType == TSDB_DATA_TYPE_INT ? pCtx->param[0].i64Key : pCtx->param[0].dKey;
|
double v = pCtx->param[0].nType == TSDB_DATA_TYPE_INT ? pCtx->param[0].i64Key : pCtx->param[0].dKey;
|
||||||
|
|
||||||
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
|
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||||
tMemBucket * pMemBucket = ((SPercentileInfo *)GET_ROWCELL_INTERBUF(pResInfo))->pMemBucket;
|
SPercentileInfo* ppInfo = (SPercentileInfo *) GET_ROWCELL_INTERBUF(pResInfo);
|
||||||
|
|
||||||
if (pMemBucket->total > 0) { // check for null
|
tMemBucket * pMemBucket = ppInfo->pMemBucket;
|
||||||
*(double *)pCtx->aOutputBuf = getPercentile(pMemBucket, v);
|
if (pMemBucket == NULL || pMemBucket->total == 0) { // check for null
|
||||||
} else {
|
assert(ppInfo->numOfElems == 0);
|
||||||
setNull(pCtx->aOutputBuf, pCtx->outputType, pCtx->outputBytes);
|
setNull(pCtx->aOutputBuf, pCtx->outputType, pCtx->outputBytes);
|
||||||
|
} else {
|
||||||
|
*(double *)pCtx->aOutputBuf = getPercentile(pMemBucket, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
tMemBucketDestroy(pMemBucket);
|
tMemBucketDestroy(pMemBucket);
|
||||||
|
|
Loading…
Reference in New Issue