fix: multi/div with timestamp type

This commit is contained in:
factosea 2024-12-16 16:51:45 +08:00
parent 07aea5e350
commit b195b7fa12
3 changed files with 9 additions and 5 deletions

View File

@ -149,7 +149,7 @@ int32_t vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarPara
int32_t _ord, int32_t optr);
int32_t vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr);
bool checkOperatorRestypeIsTimestamp(int32_t ldt, int32_t rdt);
bool checkOperatorRestypeIsTimestamp(EOperatorType opType, int32_t ldt, int32_t rdt);
#ifdef __cplusplus
}

View File

@ -1693,7 +1693,7 @@ static int32_t sclGetMathOperatorResType(SOperatorNode *pOp) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
if (checkOperatorRestypeIsTimestamp(ldt.type, rdt.type)) {
if (checkOperatorRestypeIsTimestamp(pOp->opType, ldt.type, rdt.type)) {
pOp->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
} else {

View File

@ -24,6 +24,7 @@
#include "tcompare.h"
#include "tdatablock.h"
#include "tdataformat.h"
#include "tdef.h"
#include "ttime.h"
#include "ttypes.h"
#include "geosWrapper.h"
@ -1261,7 +1262,7 @@ int32_t vectorMathAdd(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *p
SColumnInfoData *pRightCol = NULL;
SCL_ERR_JRET(vectorConvertVarToDouble(pLeft, &leftConvert, &pLeftCol));
SCL_ERR_JRET(vectorConvertVarToDouble(pRight, &rightConvert, &pRightCol));
if(checkOperatorRestypeIsTimestamp(GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight))) { // timestamp plus duration
if(checkOperatorRestypeIsTimestamp(OP_TYPE_ADD, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight))) { // timestamp plus duration
int64_t *output = (int64_t *)pOutputCol->pData;
_getBigintValue_fn_t getVectorBigintValueFnLeft;
_getBigintValue_fn_t getVectorBigintValueFnRight;
@ -1393,7 +1394,7 @@ int32_t vectorMathSub(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *p
SCL_ERR_JRET(vectorConvertVarToDouble(pLeft, &leftConvert, &pLeftCol));
SCL_ERR_JRET(vectorConvertVarToDouble(pRight, &rightConvert, &pRightCol));
if (checkOperatorRestypeIsTimestamp(GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight))) { // timestamp minus duration
if (checkOperatorRestypeIsTimestamp(OP_TYPE_SUB, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight))) { // timestamp minus duration
int64_t *output = (int64_t *)pOutputCol->pData;
_getBigintValue_fn_t getVectorBigintValueFnLeft;
_getBigintValue_fn_t getVectorBigintValueFnRight;
@ -2297,7 +2298,10 @@ _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) {
}
}
bool checkOperatorRestypeIsTimestamp(int32_t lType, int32_t rType) {
bool checkOperatorRestypeIsTimestamp(EOperatorType opType, int32_t lType, int32_t rType) {
if (opType != OP_TYPE_ADD && opType != OP_TYPE_SUB && opType != OP_TYPE_MINUS) {
return false;
}
if ((TSDB_DATA_TYPE_TIMESTAMP == lType && IS_INTEGER_TYPE(rType) && rType != TSDB_DATA_TYPE_UBIGINT) ||
(TSDB_DATA_TYPE_TIMESTAMP == rType && IS_INTEGER_TYPE(lType) && lType != TSDB_DATA_TYPE_UBIGINT) ||
(TSDB_DATA_TYPE_TIMESTAMP == lType && TSDB_DATA_TYPE_BOOL == rType) ||