提交 f3b34b1e 编写于 作者: S shenglian zhou

[TD-10735]<fix>:use different cumsum type for signed/unsigned/double input type

上级 30e7b87c
......@@ -20,7 +20,6 @@
#include "tdigest.h"
#include "ttype.h"
#include "tsdb.h"
#include "tglobal.h"
#include "qAggMain.h"
#include "qFill.h"
......@@ -172,7 +171,11 @@ typedef struct SDerivInfo {
} SDerivInfo;
typedef struct {
double cumSum;
union {
double d64CumSum;
int64_t i64CumSum;
uint64_t u64CumSum;
};
} SCumSumInfo;
typedef struct {
......@@ -4709,7 +4712,7 @@ static bool csum_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResIn
}
SCumSumInfo* pCumSumInfo = GET_ROWCELL_INTERBUF(pResInfo);
pCumSumInfo->cumSum = 0;
pCumSumInfo->i64CumSum = 0;
return true;
}
......@@ -4733,20 +4736,30 @@ static void csum_function(SQLFunctionCtx *pCtx) {
continue;
}
double v = 0;
GET_TYPED_DATA(v, double, pCtx->inputType, pData);
pCumSumInfo->cumSum += v;
if (IS_SIGNED_NUMERIC_TYPE(pCtx->inputType)) {
int64_t v = 0;
GET_TYPED_DATA(v, int64_t, pCtx->inputType, pData);
pCumSumInfo->i64CumSum += v;
} else if (IS_UNSIGNED_NUMERIC_TYPE(pCtx->inputType)) {
uint64_t v = 0;
GET_TYPED_DATA(v, uint64_t, pCtx->inputType, pData);
pCumSumInfo->u64CumSum += v;
} else if (IS_FLOAT_TYPE(pCtx->inputType)) {
double v = 0;
GET_TYPED_DATA(v, double, pCtx->inputType, pData);
pCumSumInfo->d64CumSum += v;
}
*pTimestamp = (tsList != NULL) ? tsList[i] : 0;
if (IS_SIGNED_NUMERIC_TYPE(pCtx->inputType)) {
int64_t *retVal = (int64_t *)pCtx->pOutput;
*retVal = (int64_t)(pCumSumInfo->cumSum);
*retVal = (int64_t)(pCumSumInfo->i64CumSum);
} else if (IS_UNSIGNED_NUMERIC_TYPE(pCtx->inputType)) {
uint64_t *retVal = (uint64_t *)pCtx->pOutput;
*retVal = (uint64_t)(pCumSumInfo->cumSum);
*retVal = (uint64_t)(pCumSumInfo->u64CumSum);
} else if (IS_FLOAT_TYPE(pCtx->inputType)) {
double *retVal = (double*) pCtx->pOutput;
SET_DOUBLE_VAL(retVal, pCumSumInfo->cumSum);
SET_DOUBLE_VAL(retVal, pCumSumInfo->d64CumSum);
}
++notNullElems;
......
......@@ -88,6 +88,18 @@ sql select csum(tbcol) as b from $tb where ts <= $ms interval(1m) -x step6
return -1
step6:
print =============== csum result overflow follow sum behavior
sql create table overflow(ts timestamp, c1 bigint)
sql insert into overflow values(now-1s, NULL)(now, 9223372036854775807)(now+1s, 9223372036854775807)
sql select csum(c1) from overflow
print $data00 , $data01, $data10, $data11
if $data01 != 9223372036854775807 then
return -1
endi
if $data11 != -2 then
return -1
endi
print =============== clear
sql drop database $db
sql show databases
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册