From 0174dcae883be694b0d7078b3a0a6f8730ce463b Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Wed, 20 Oct 2021 14:07:52 +0800 Subject: [PATCH] :set NULL when NULL input during scalar function --- src/query/src/qAggMain.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 8ef221dc7e..e9fb854584 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -5546,7 +5546,7 @@ SAggFunctionInfo aAggs[] = {{ static void scalar_function(SQLFunctionCtx *pCtx) { SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); - int32_t notNullElems = 0; + int32_t numElems = 0; int32_t step = GET_FORWARD_DIRECTION_FACTOR(pCtx->order); int32_t i = (pCtx->order == TSDB_ORDER_ASC) ? 0 : pCtx->size -1; @@ -5556,24 +5556,28 @@ static void scalar_function(SQLFunctionCtx *pCtx) { for (; i < pCtx->size && i >= 0; i += step) { char* pData = GET_INPUT_DATA(pCtx, i); - if (pCtx->hasNull && isNull(pData, pCtx->inputType)) { - qDebug("%p scalar_function() index of null data:%d", pCtx, i); - continue; - } switch (pCtx->functionId) { case TSDB_FUNC_SCALAR_POW: { - double v = 0; - GET_TYPED_DATA(v, double, pCtx->inputType, pData); - double result = pow(v, pCtx->param[0].dKey); - SET_TYPED_DATA(pCtx->pOutput, pCtx->outputType, result); + if (pCtx->hasNull && isNull(pData, pCtx->inputType)) { + setNull(pCtx->pOutput, TSDB_DATA_TYPE_DOUBLE, tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes); + } else { + double v = 0; + GET_TYPED_DATA(v, double, pCtx->inputType, pData); + double result = pow(v, pCtx->param[0].dKey); + SET_TYPED_DATA(pCtx->pOutput, pCtx->outputType, result); + } break; } case TSDB_FUNC_SCALAR_LOG: { - double v = 0; - GET_TYPED_DATA(v, double, pCtx->inputType, pData); - double result = log(v)/ log(pCtx->param[0].dKey); - SET_TYPED_DATA(pCtx->pOutput, pCtx->outputType, result); + if (pCtx->hasNull && isNull(pData, pCtx->inputType)) { + setNull(pCtx->pOutput, TSDB_DATA_TYPE_DOUBLE, tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes); + } else { + double v = 0; + GET_TYPED_DATA(v, double, pCtx->inputType, pData); + double result = log(v) / log(pCtx->param[0].dKey); + SET_TYPED_DATA(pCtx->pOutput, pCtx->outputType, result); + } break; } default: @@ -5581,15 +5585,13 @@ static void scalar_function(SQLFunctionCtx *pCtx) { break; } - ++notNullElems; + ++numElems; pCtx->pOutput += pCtx->outputBytes; pTimestamp++; } - if (notNullElems == 0) { - assert(pCtx->hasNull); - } else { - pResInfo->numOfRes += notNullElems; + if (numElems != 0) { + pResInfo->numOfRes += numElems; pResInfo->hasResult = DATA_SET_FLAG; } } -- GitLab