提交 5fdb5567 编写于 作者: H Haojun Liao

[td-3016] <fix>: fix sum error for unsigned data type.

上级 34412d8d
...@@ -92,8 +92,9 @@ typedef struct SSpreadInfo { ...@@ -92,8 +92,9 @@ typedef struct SSpreadInfo {
typedef struct SSumInfo { typedef struct SSumInfo {
union { union {
int64_t isum; int64_t isum;
double dsum; uint64_t usum;
double dsum;
}; };
int8_t hasResult; int8_t hasResult;
} SSumInfo; } SSumInfo;
...@@ -595,6 +596,18 @@ static void do_sum_f(SQLFunctionCtx *pCtx, int32_t index) { ...@@ -595,6 +596,18 @@ static void do_sum_f(SQLFunctionCtx *pCtx, int32_t index) {
*res += GET_INT32_VAL(pData); *res += GET_INT32_VAL(pData);
} else if (pCtx->inputType == TSDB_DATA_TYPE_BIGINT) { } else if (pCtx->inputType == TSDB_DATA_TYPE_BIGINT) {
*res += GET_INT64_VAL(pData); *res += GET_INT64_VAL(pData);
} else if (pCtx->inputType == TSDB_DATA_TYPE_UTINYINT) {
uint64_t *r = (uint64_t *)pCtx->pOutput;
*r += GET_UINT8_VAL(pData);
} else if (pCtx->inputType == TSDB_DATA_TYPE_USMALLINT) {
uint64_t *r = (uint64_t *)pCtx->pOutput;
*r += GET_UINT16_VAL(pData);
} else if (pCtx->inputType == TSDB_DATA_TYPE_UINT) {
uint64_t *r = (uint64_t *)pCtx->pOutput;
*r += GET_UINT32_VAL(pData);
} else if (pCtx->inputType == TSDB_DATA_TYPE_UBIGINT) {
uint64_t *r = (uint64_t *)pCtx->pOutput;
*r += GET_UINT64_VAL(pData);
} else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE) { } else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE) {
double *retVal = (double*) pCtx->pOutput; double *retVal = (double*) pCtx->pOutput;
*retVal += GET_DOUBLE_VAL(pData); *retVal += GET_DOUBLE_VAL(pData);
...@@ -644,18 +657,12 @@ static void sum_func_merge(SQLFunctionCtx *pCtx) { ...@@ -644,18 +657,12 @@ static void sum_func_merge(SQLFunctionCtx *pCtx) {
notNullElems++; notNullElems++;
switch (type) { if (IS_SIGNED_NUMERIC_TYPE(type)) {
case TSDB_DATA_TYPE_TINYINT: *(int64_t *)pCtx->pOutput += pInput->isum;
case TSDB_DATA_TYPE_SMALLINT: } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
case TSDB_DATA_TYPE_INT: *(uint64_t *) pCtx->pOutput += pInput->usum;
case TSDB_DATA_TYPE_BIGINT: { } else {
*(int64_t *)pCtx->pOutput += pInput->isum; *(double *)pCtx->pOutput += pInput->dsum;
break;
};
case TSDB_DATA_TYPE_FLOAT:
case TSDB_DATA_TYPE_DOUBLE: {
*(double *)pCtx->pOutput += pInput->dsum;
}
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册