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

This commit is contained in:
Haojun Liao 2021-03-02 11:11:28 +08:00
parent 34412d8da8
commit 5fdb5567eb
1 changed files with 21 additions and 14 deletions

View File

@ -93,6 +93,7 @@ typedef struct SSpreadInfo {
typedef struct SSumInfo { typedef struct SSumInfo {
union { union {
int64_t isum; int64_t isum;
uint64_t usum;
double dsum; double dsum;
}; };
int8_t hasResult; int8_t hasResult;
@ -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,20 +657,14 @@ static void sum_func_merge(SQLFunctionCtx *pCtx) {
notNullElems++; notNullElems++;
switch (type) { if (IS_SIGNED_NUMERIC_TYPE(type)) {
case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_SMALLINT:
case TSDB_DATA_TYPE_INT:
case TSDB_DATA_TYPE_BIGINT: {
*(int64_t *)pCtx->pOutput += pInput->isum; *(int64_t *)pCtx->pOutput += pInput->isum;
break; } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
}; *(uint64_t *) pCtx->pOutput += pInput->usum;
case TSDB_DATA_TYPE_FLOAT: } else {
case TSDB_DATA_TYPE_DOUBLE: {
*(double *)pCtx->pOutput += pInput->dsum; *(double *)pCtx->pOutput += pInput->dsum;
} }
} }
}
SET_VAL(pCtx, notNullElems, 1); SET_VAL(pCtx, notNullElems, 1);
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);