From e948d5a2483f3d6da8ee822d6b66cba51a2f6ab7 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 18 May 2022 16:35:13 +0800 Subject: [PATCH] enh(query): support avg(NULL), stddev(NULL) --- source/libs/function/src/builtins.c | 2 +- source/libs/function/src/builtinsimpl.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index d58df3e876..306b438344 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -63,7 +63,7 @@ static int32_t translateInNumOutDou(SFunctionNode* pFunc, char* pErrBuf, int32_t } uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; - if (!IS_NUMERIC_TYPE(paraType)) { + if (!IS_NUMERIC_TYPE(paraType) && !IS_NULL_TYPE(paraType)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 77126225bf..90632256b2 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -542,6 +542,12 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) { int32_t start = pInput->startRowIndex; int32_t numOfRows = pInput->numOfRows; + if (IS_NULL_TYPE(type)) { + GET_RES_INFO(pCtx)->isNullRes = 1; + numOfElem = 1; + goto _avg_over; + } + switch (type) { case TSDB_DATA_TYPE_TINYINT: { int8_t* plist = (int8_t*)pCol->pData; @@ -633,6 +639,7 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) { break; } +_avg_over: // data in the check operation are all null, not output SET_VAL(GET_RES_INFO(pCtx), numOfElem, 1); return TSDB_CODE_SUCCESS; @@ -1330,6 +1337,12 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) { int32_t start = pInput->startRowIndex; int32_t numOfRows = pInput->numOfRows; + if (IS_NULL_TYPE(type)) { + GET_RES_INFO(pCtx)->isNullRes = 1; + numOfElem = 1; + goto _stddev_over; + } + switch (type) { case TSDB_DATA_TYPE_TINYINT: { int8_t* plist = (int8_t*)pCol->pData; @@ -1427,6 +1440,7 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) { break; } +_stddev_over: // data in the check operation are all null, not output SET_VAL(GET_RES_INFO(pCtx), numOfElem, 1); return TSDB_CODE_SUCCESS; -- GitLab