set decimal type expr res types

This commit is contained in:
wangjiaming0909 2024-12-31 10:31:13 +08:00
parent eb7b35881a
commit b958d3a397
4 changed files with 21 additions and 12 deletions

View File

@ -9,7 +9,7 @@ uint64_t uInt128Lo(const UInt128* pInt) { return *pInt & 0xFFFFFFFFFFFFFFFF; }
void uInt128Abs(UInt128* pInt); void uInt128Abs(UInt128* pInt);
void uInt128Add(UInt128* pLeft, const UInt128* pRight) { *pLeft += *pRight; } void uInt128Add(UInt128* pLeft, const UInt128* pRight) { *pLeft += *pRight; }
void uInt128Subtract(UInt128* pLeft, const UInt128* 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 uInt128Divide(UInt128* pLeft, const UInt128* pRight) { *pLeft /= *pRight; }
void uInt128Mod(UInt128* pLeft, const UInt128* pRight) { *pLeft %= *pRight; } void uInt128Mod(UInt128* pLeft, const UInt128* pRight) { *pLeft %= *pRight; }
bool uInt128Lt(const UInt128* pLeft, const UInt128* pRight); bool uInt128Lt(const UInt128* pLeft, const UInt128* pRight);

View File

@ -1721,6 +1721,8 @@ static int32_t sclGetMathOperatorResType(SOperatorNode *pOp) {
SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType; SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType;
SDataType rdt = ((SExprNode *)(pOp->pRight))->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) || 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 || 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.type = TSDB_DATA_TYPE_TIMESTAMP;
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes; pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
} else { } else {
pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE; if (hasDecimalType && !hasFloatType) {
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; 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; return TSDB_CODE_SUCCESS;
} }

View File

@ -1220,11 +1220,9 @@ int32_t vectorMathAdd(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *p
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
int32_t leftConvert = 0, rightConvert = 0; int32_t leftConvert = 0, rightConvert = 0;
SColumnInfoData *pLeftCol = NULL; SColumnInfoData *pLeftCol = pLeft->columnData;
SColumnInfoData *pRightCol = NULL; SColumnInfoData *pRightCol = pRight->columnData;
SCL_ERR_JRET(vectorConvertVarToDouble(pLeft, &leftConvert, &pLeftCol)); if(pOutputCol->info.type == TSDB_DATA_TYPE_TIMESTAMP) { // timestamp plus duration
SCL_ERR_JRET(vectorConvertVarToDouble(pRight, &rightConvert, &pRightCol));
if(checkOperatorRestypeIsTimestamp(OP_TYPE_ADD, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight))) { // timestamp plus duration
int64_t *output = (int64_t *)pOutputCol->pData; int64_t *output = (int64_t *)pOutputCol->pData;
_getBigintValue_fn_t getVectorBigintValueFnLeft; _getBigintValue_fn_t getVectorBigintValueFnLeft;
_getBigintValue_fn_t getVectorBigintValueFnRight; _getBigintValue_fn_t getVectorBigintValueFnRight;
@ -1254,7 +1252,9 @@ int32_t vectorMathAdd(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *p
*output = leftRes + rightRes; *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; double *output = (double *)pOutputCol->pData;
_getDoubleValue_fn_t getVectorDoubleValueFnLeft; _getDoubleValue_fn_t getVectorDoubleValueFnLeft;
_getDoubleValue_fn_t getVectorDoubleValueFnRight; _getDoubleValue_fn_t getVectorDoubleValueFnRight;
@ -1277,6 +1277,8 @@ int32_t vectorMathAdd(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *p
} else if (pRight->numOfRows == 1) { } else if (pRight->numOfRows == 1) {
SCL_ERR_JRET(vectorMathAddHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i)); SCL_ERR_JRET(vectorMathAddHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i));
} }
} else if (IS_DECIMAL_TYPE(pOutputCol->info.type)) {
} }
_return: _return:

View File

@ -261,7 +261,7 @@ class TDTestCase:
self.columns = [] self.columns = []
self.tags = [] self.tags = []
self.stable_name = "meters" self.stable_name = "meters"
self.norm_table_name = "norm_table" self.norm_table_name = "nt"
self.c_table_prefix = "t" self.c_table_prefix = "t"
self.db_name = "test" self.db_name = "test"
self.c_table_num = 10 self.c_table_num = 10
@ -430,8 +430,8 @@ class TDTestCase:
self.check_show_create_table("meters", self.columns, self.tags) self.check_show_create_table("meters", self.columns, self.tags)
DecimalColumnTableCreater(tdSql, self.db_name, self.norm_table_name, self.columns).create() DecimalColumnTableCreater(tdSql, self.db_name, self.norm_table_name, self.columns).create()
self.check_desc("norm_table", self.columns) self.check_desc(self.norm_table_name, self.columns)
self.check_show_create_table("norm_table", self.columns) self.check_show_create_table(self.norm_table_name, self.columns)
## TODO add more values for all rows ## TODO add more values for all rows
tag_values = [ tag_values = [