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

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

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