diff --git a/source/libs/decimal/src/wideInteger.c b/source/libs/decimal/src/wideInteger.c index 03823e5e28..c514cab7d7 100644 --- a/source/libs/decimal/src/wideInteger.c +++ b/source/libs/decimal/src/wideInteger.c @@ -9,7 +9,7 @@ uint64_t uInt128Lo(const UInt128* pInt) { return *pInt & 0xFFFFFFFFFFFFFFFF; } void uInt128Abs(UInt128* pInt); void uInt128Add(UInt128* pLeft, const UInt128* pRight) { *pLeft += *pRight; } void uInt128Subtract(UInt128* pLeft, const UInt128* pRight); -void uInt128Multiply(UInt128* pLeft, const UInt128* pRight) { *pLeft = *pLeft * *pRight; } +void uInt128Multiply(UInt128* pLeft, const UInt128* pRight) { *pLeft *= *pRight; } void uInt128Divide(UInt128* pLeft, const UInt128* pRight) { *pLeft /= *pRight; } void uInt128Mod(UInt128* pLeft, const UInt128* pRight) { *pLeft %= *pRight; } bool uInt128Lt(const UInt128* pLeft, const UInt128* pRight); diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 9bab697772..46a7f9b772 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -1721,6 +1721,8 @@ static int32_t sclGetMathOperatorResType(SOperatorNode *pOp) { SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType; SDataType rdt = ((SExprNode *)(pOp->pRight))->resType; + bool hasFloatType = IS_FLOAT_TYPE(ldt.type) || IS_FLOAT_TYPE(rdt.type); + bool hasDecimalType = IS_DECIMAL_TYPE(ldt.type) || IS_DECIMAL_TYPE(rdt.type); if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_TIMESTAMP == rdt.type) || TSDB_DATA_TYPE_VARBINARY == ldt.type || TSDB_DATA_TYPE_VARBINARY == rdt.type || @@ -1733,8 +1735,13 @@ static int32_t sclGetMathOperatorResType(SOperatorNode *pOp) { pOp->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP; pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes; } else { - pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE; - pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; + if (hasDecimalType && !hasFloatType) { + pOp->node.resType.type = TSDB_DATA_TYPE_DECIMAL; + pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DECIMAL].bytes; + } else { + pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE; + pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; + } } return TSDB_CODE_SUCCESS; } diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index ff45baa1e0..4239b8c940 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -1220,11 +1220,9 @@ int32_t vectorMathAdd(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *p int32_t code = TSDB_CODE_SUCCESS; int32_t leftConvert = 0, rightConvert = 0; - SColumnInfoData *pLeftCol = NULL; - SColumnInfoData *pRightCol = NULL; - SCL_ERR_JRET(vectorConvertVarToDouble(pLeft, &leftConvert, &pLeftCol)); - SCL_ERR_JRET(vectorConvertVarToDouble(pRight, &rightConvert, &pRightCol)); - if(checkOperatorRestypeIsTimestamp(OP_TYPE_ADD, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight))) { // timestamp plus duration + SColumnInfoData *pLeftCol = pLeft->columnData; + SColumnInfoData *pRightCol = pRight->columnData; + if(pOutputCol->info.type == TSDB_DATA_TYPE_TIMESTAMP) { // timestamp plus duration int64_t *output = (int64_t *)pOutputCol->pData; _getBigintValue_fn_t getVectorBigintValueFnLeft; _getBigintValue_fn_t getVectorBigintValueFnRight; @@ -1254,7 +1252,9 @@ int32_t vectorMathAdd(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *p *output = leftRes + rightRes; } } - } else { + } else if (pOutputCol->info.type == TSDB_DATA_TYPE_DOUBLE){ + SCL_ERR_JRET(vectorConvertVarToDouble(pLeft, &leftConvert, &pLeftCol)); + SCL_ERR_JRET(vectorConvertVarToDouble(pRight, &rightConvert, &pRightCol)); double *output = (double *)pOutputCol->pData; _getDoubleValue_fn_t getVectorDoubleValueFnLeft; _getDoubleValue_fn_t getVectorDoubleValueFnRight; @@ -1277,6 +1277,8 @@ int32_t vectorMathAdd(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *p } else if (pRight->numOfRows == 1) { SCL_ERR_JRET(vectorMathAddHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i)); } + } else if (IS_DECIMAL_TYPE(pOutputCol->info.type)) { + } _return: diff --git a/tests/system-test/2-query/decimal.py b/tests/system-test/2-query/decimal.py index ab72ed3c9b..dbf5943164 100644 --- a/tests/system-test/2-query/decimal.py +++ b/tests/system-test/2-query/decimal.py @@ -261,7 +261,7 @@ class TDTestCase: self.columns = [] self.tags = [] self.stable_name = "meters" - self.norm_table_name = "norm_table" + self.norm_table_name = "nt" self.c_table_prefix = "t" self.db_name = "test" self.c_table_num = 10 @@ -430,8 +430,8 @@ class TDTestCase: self.check_show_create_table("meters", self.columns, self.tags) DecimalColumnTableCreater(tdSql, self.db_name, self.norm_table_name, self.columns).create() - self.check_desc("norm_table", self.columns) - self.check_show_create_table("norm_table", self.columns) + self.check_desc(self.norm_table_name, self.columns) + self.check_show_create_table(self.norm_table_name, self.columns) ## TODO add more values for all rows tag_values = [