From a52e0027cf6508a562a4ed04ba30c90763c46fe4 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 18 May 2022 16:03:59 +0800 Subject: [PATCH] enh(query): support count(NULL) = 0 --- source/libs/function/src/builtinsimpl.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index d8d7a2f62e..77126225bf 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -330,8 +330,18 @@ static FORCE_INLINE int32_t getNumofElem(SqlFunctionCtx* pCtx) { int32_t countFunction(SqlFunctionCtx* pCtx) { int32_t numOfElem = getNumofElem(pCtx); SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); - char* buf = GET_ROWCELL_INTERBUF(pResInfo); - *((int64_t*)buf) += numOfElem; + + SInputColumnInfoData* pInput = &pCtx->input; + int32_t type = pInput->pData[0]->info.type; + + char* buf = GET_ROWCELL_INTERBUF(pResInfo); + if (IS_NULL_TYPE(type)) { + //select count(NULL) returns 0 + numOfElem = 1; + *((int64_t*)buf) = 0; + } else { + *((int64_t*)buf) += numOfElem; + } SET_VAL(pResInfo, numOfElem, 1); return TSDB_CODE_SUCCESS; -- GitLab