From 1e503061ede124044e336fa4e1a34342fb508d96 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 12 May 2022 20:40:17 +0800 Subject: [PATCH] feat(query): add mavg function --- source/libs/function/src/builtinsimpl.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index fd8c9fd79c..5ce8272234 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -3013,18 +3013,22 @@ int32_t mavgFunction(SqlFunctionCtx* pCtx) { } else { pInfo->sum = pInfo->sum + v - pInfo->points[pInfo->pos]; } - } - pInfo->points[pInfo->pos] = v; - double result = pInfo->sum / pInfo->numOfPoints; - colDataAppend(pOutput, pos, (char *)&result, false); + pInfo->points[pInfo->pos] = v; + double result = pInfo->sum / pInfo->numOfPoints; + colDataAppend(pOutput, pos, (char *)&result, false); - //TODO: remove this after pTsOutput is handled - if (pTsOutput != NULL) { - colDataAppendInt64(pTsOutput, pos, &tsList[i]); + //TODO: remove this after pTsOutput is handled + if (pTsOutput != NULL) { + colDataAppendInt64(pTsOutput, pos, &tsList[i]); + } + numOfElems++; } - numOfElems++; + pInfo->pos++; + if (pInfo->pos == pInfo->numOfPoints) { + pInfo->pos = 0; + } } return numOfElems; -- GitLab