From 0b3a3aff214fc27d78fe51230c98d99b1d3737ed Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 3 Nov 2022 15:01:52 +0800 Subject: [PATCH] fix hll tsCountAlwaysReturnValue not working --- source/libs/function/src/builtinsimpl.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 9ae169bcf4..889d3aeda9 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -181,6 +181,7 @@ typedef enum { UNKNOWN_BIN = 0, USER_INPUT_BIN, LINEAR_BIN, LOG_BIN } EHistoBinT typedef struct SHLLFuncInfo { uint64_t result; + uint64_t totalCount; uint8_t buckets[HLL_BUCKETS]; } SHLLInfo; @@ -4605,7 +4606,14 @@ int32_t hllFunction(SqlFunctionCtx* pCtx) { } } - SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1); + pInfo->totalCount += numOfElems; + + if (pInfo->totalCount == 0 && !tsCountAlwaysReturnValue) { + SET_VAL(GET_RES_INFO(pCtx), 0, 1); + } else { + SET_VAL(GET_RES_INFO(pCtx), 1, 1); + } + return TSDB_CODE_SUCCESS; } @@ -4615,6 +4623,7 @@ static void hllTransferInfo(SHLLInfo* pInput, SHLLInfo* pOutput) { pOutput->buckets[k] = pInput->buckets[k]; } } + pOutput->totalCount += pInput->totalCount; } int32_t hllFunctionMerge(SqlFunctionCtx* pCtx) { @@ -4632,7 +4641,12 @@ int32_t hllFunctionMerge(SqlFunctionCtx* pCtx) { hllTransferInfo(pInputInfo, pInfo); } - SET_VAL(GET_RES_INFO(pCtx), 1, 1); + if (pInfo->totalCount == 0 && !tsCountAlwaysReturnValue) { + SET_VAL(GET_RES_INFO(pCtx), 0, 1); + } else { + SET_VAL(GET_RES_INFO(pCtx), 1, 1); + } + return TSDB_CODE_SUCCESS; } -- GitLab