fix decimal op test
This commit is contained in:
parent
c955c23076
commit
7a1ffd92ac
|
@ -90,6 +90,7 @@ int32_t decimal128ToDataVal(Decimal128* dec, SValue* pVal);
|
||||||
int32_t decimalToStr(const DecimalType* pDec, int8_t type, int8_t precision, int8_t scale, char* pBuf, int32_t bufLen);
|
int32_t decimalToStr(const DecimalType* pDec, int8_t type, int8_t precision, int8_t scale, char* pBuf, int32_t bufLen);
|
||||||
|
|
||||||
int32_t decimalGetRetType(const SDataType* pLeftT, const SDataType* pRightT, EOperatorType opType, SDataType* pOutType);
|
int32_t decimalGetRetType(const SDataType* pLeftT, const SDataType* pRightT, EOperatorType opType, SDataType* pOutType);
|
||||||
|
bool decimal64Compare(EOperatorType op, const SDecimalCompareCtx* pLeft, const SDecimalCompareCtx* pRight);
|
||||||
bool decimalCompare(EOperatorType op, const SDecimalCompareCtx* pLeft, const SDecimalCompareCtx* pRight);
|
bool decimalCompare(EOperatorType op, const SDecimalCompareCtx* pLeft, const SDecimalCompareCtx* pRight);
|
||||||
int32_t decimalOp(EOperatorType op, const SDataType* pLeftT, const SDataType* pRightT, const SDataType* pOutT,
|
int32_t decimalOp(EOperatorType op, const SDataType* pLeftT, const SDataType* pRightT, const SDataType* pOutT,
|
||||||
const void* pLeftData, const void* pRightData, void* pOutputData);
|
const void* pLeftData, const void* pRightData, void* pOutputData);
|
||||||
|
|
|
@ -1125,6 +1125,71 @@ int32_t decimalOp(EOperatorType op, const SDataType* pLeftT, const SDataType* pR
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool doCompareDecimal128(EOperatorType op, const Decimal128* pLeftDec, const Decimal128* pRightDec) {
|
||||||
|
switch (op) {
|
||||||
|
case OP_TYPE_GREATER_THAN:
|
||||||
|
return decimal128Gt(pLeftDec, pRightDec, WORD_NUM(Decimal));
|
||||||
|
case OP_TYPE_GREATER_EQUAL:
|
||||||
|
return !decimal128Lt(pLeftDec, pRightDec, WORD_NUM(Decimal));
|
||||||
|
case OP_TYPE_LOWER_THAN:
|
||||||
|
return decimal128Lt(pLeftDec, pRightDec, WORD_NUM(Decimal));
|
||||||
|
case OP_TYPE_LOWER_EQUAL:
|
||||||
|
return !decimal128Gt(pLeftDec, pRightDec, WORD_NUM(Decimal));
|
||||||
|
case OP_TYPE_EQUAL:
|
||||||
|
return decimal128Eq(pLeftDec, pRightDec, WORD_NUM(Decimal));
|
||||||
|
case OP_TYPE_NOT_EQUAL:
|
||||||
|
return !decimal128Eq(pLeftDec, pRightDec, WORD_NUM(Decimal));
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool decimal64Compare(EOperatorType op, const SDecimalCompareCtx* pLeft, const SDecimalCompareCtx* pRight) {
|
||||||
|
bool ret = false;
|
||||||
|
uint8_t leftPrec = 0, leftScale = 0, rightPrec = 0, rightScale = 0;
|
||||||
|
decimalFromTypeMod(pLeft->typeMod, &leftPrec, &leftScale);
|
||||||
|
decimalFromTypeMod(pRight->typeMod, &rightPrec, &rightScale);
|
||||||
|
int32_t deltaScale = leftScale - rightScale;
|
||||||
|
|
||||||
|
Decimal64 leftDec = *(Decimal64*)pLeft->pData, rightDec = *(Decimal64*)pRight->pData;
|
||||||
|
|
||||||
|
if (deltaScale != 0) {
|
||||||
|
bool needInt128 = (deltaScale < 0 && leftPrec - deltaScale > TSDB_DECIMAL64_MAX_PRECISION) ||
|
||||||
|
(rightPrec + deltaScale > TSDB_DECIMAL64_MAX_PRECISION);
|
||||||
|
if (needInt128) {
|
||||||
|
Decimal128 dec128L = {0}, dec128R = {0};
|
||||||
|
makeDecimal128FromDecimal64(&dec128L, leftDec);
|
||||||
|
makeDecimal128FromDecimal64(&dec128R, rightDec);
|
||||||
|
return doCompareDecimal128(op, &dec128L, &dec128R);
|
||||||
|
} else {
|
||||||
|
if (deltaScale < 0) {
|
||||||
|
decimal64ScaleUp(&leftDec, -deltaScale);
|
||||||
|
} else {
|
||||||
|
decimal64ScaleUp(&rightDec, deltaScale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (op) {
|
||||||
|
case OP_TYPE_GREATER_THAN:
|
||||||
|
return decimal64Gt(&leftDec, &rightDec, WORD_NUM(Decimal64));
|
||||||
|
case OP_TYPE_GREATER_EQUAL:
|
||||||
|
return !decimal64Lt(&leftDec, &rightDec, WORD_NUM(Decimal64));
|
||||||
|
case OP_TYPE_LOWER_THAN:
|
||||||
|
return decimal64Lt(&leftDec, &rightDec, WORD_NUM(Decimal64));
|
||||||
|
case OP_TYPE_LOWER_EQUAL:
|
||||||
|
return !decimal64Gt(&leftDec, &rightDec, WORD_NUM(Decimal64));
|
||||||
|
case OP_TYPE_EQUAL:
|
||||||
|
return decimal64Eq(&leftDec, &rightDec, WORD_NUM(Decimal64));
|
||||||
|
case OP_TYPE_NOT_EQUAL:
|
||||||
|
return !decimal64Eq(&leftDec, &rightDec, WORD_NUM(Decimal64));
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
// There is no need to do type conversions, we assume that pLeftT and pRightT are all decimal128 types.
|
// There is no need to do type conversions, we assume that pLeftT and pRightT are all decimal128 types.
|
||||||
bool decimalCompare(EOperatorType op, const SDecimalCompareCtx* pLeft, const SDecimalCompareCtx* pRight) {
|
bool decimalCompare(EOperatorType op, const SDecimalCompareCtx* pLeft, const SDecimalCompareCtx* pRight) {
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
@ -1171,24 +1236,7 @@ bool decimalCompare(EOperatorType op, const SDecimalCompareCtx* pLeft, const SDe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return doCompareDecimal128(op, &pLeftDec, &pRightDec);
|
||||||
switch (op) {
|
|
||||||
case OP_TYPE_GREATER_THAN:
|
|
||||||
return decimal128Gt(&pLeftDec, &pRightDec, WORD_NUM(Decimal));
|
|
||||||
case OP_TYPE_GREATER_EQUAL:
|
|
||||||
return !decimal128Lt(&pLeftDec, &pRightDec, WORD_NUM(Decimal));
|
|
||||||
case OP_TYPE_LOWER_THAN:
|
|
||||||
return decimal128Lt(&pLeftDec, &pRightDec, WORD_NUM(Decimal));
|
|
||||||
case OP_TYPE_LOWER_EQUAL:
|
|
||||||
return !decimal128Gt(&pLeftDec, &pRightDec, WORD_NUM(Decimal));
|
|
||||||
case OP_TYPE_EQUAL:
|
|
||||||
return decimal128Eq(&pLeftDec, &pRightDec, WORD_NUM(Decimal));
|
|
||||||
case OP_TYPE_NOT_EQUAL:
|
|
||||||
return !decimal128Eq(&pLeftDec, &pRightDec, WORD_NUM(Decimal));
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ABS_INT64(v) (v) == INT64_MIN ? (uint64_t)INT64_MAX + 1 : (uint64_t)llabs(v)
|
#define ABS_INT64(v) (v) == INT64_MIN ? (uint64_t)INT64_MAX + 1 : (uint64_t)llabs(v)
|
||||||
|
|
|
@ -11,7 +11,7 @@ if(${BUILD_WITH_ANALYSIS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(executor
|
target_link_libraries(executor
|
||||||
PRIVATE os util common function parser planner qcom scalar nodes index wal tdb geometry profiler
|
PRIVATE os util common function parser planner qcom scalar nodes index wal tdb geometry
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
|
|
||||||
#include "storageapi.h"
|
#include "storageapi.h"
|
||||||
#include "tdatablock.h"
|
#include "tdatablock.h"
|
||||||
#include "gperftools/profiler.h"
|
|
||||||
|
|
||||||
SOperatorFpSet createOperatorFpSet(__optr_open_fn_t openFn, __optr_fn_t nextFn, __optr_fn_t cleanup,
|
SOperatorFpSet createOperatorFpSet(__optr_open_fn_t openFn, __optr_fn_t nextFn, __optr_fn_t cleanup,
|
||||||
__optr_close_fn_t closeFn, __optr_reqBuf_fn_t reqBufFn, __optr_explain_fn_t explain,
|
__optr_close_fn_t closeFn, __optr_reqBuf_fn_t reqBufFn, __optr_explain_fn_t explain,
|
||||||
|
@ -283,7 +282,6 @@ int32_t stopTableScanOperator(SOperatorInfo* pOperator, const char* pIdStr, SSto
|
||||||
int32_t createOperator(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, SNode* pTagCond,
|
int32_t createOperator(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, SNode* pTagCond,
|
||||||
SNode* pTagIndexCond, const char* pUser, const char* dbname, SOperatorInfo** pOptrInfo) {
|
SNode* pTagIndexCond, const char* pUser, const char* dbname, SOperatorInfo** pOptrInfo) {
|
||||||
QRY_PARAM_CHECK(pOptrInfo);
|
QRY_PARAM_CHECK(pOptrInfo);
|
||||||
ProfilerStart("/tmp/createOperator.prof");
|
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t type = nodeType(pPhyNode);
|
int32_t type = nodeType(pPhyNode);
|
||||||
|
@ -656,7 +654,6 @@ int32_t createOperator(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHand
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroyOperator(SOperatorInfo* pOperator) {
|
void destroyOperator(SOperatorInfo* pOperator) {
|
||||||
ProfilerFlush();
|
|
||||||
if (pOperator == NULL) {
|
if (pOperator == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1045,8 +1045,8 @@ int32_t compareUint64Uint32(const void *pLeft, const void *pRight) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t compareDecimal64(const void* pleft, const void* pright) {
|
int32_t compareDecimal64(const void* pleft, const void* pright) {
|
||||||
if (decimalCompare(OP_TYPE_GREATER_THAN, pleft, pright)) return 1;
|
if (decimal64Compare(OP_TYPE_GREATER_THAN, pleft, pright)) return 1;
|
||||||
if (decimalCompare(OP_TYPE_LOWER_THAN, pleft, pright)) return -1;
|
if (decimal64Compare(OP_TYPE_LOWER_THAN, pleft, pright)) return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,11 +43,11 @@ scalar_convert_err = -2147470768
|
||||||
|
|
||||||
|
|
||||||
decimal_insert_validator_test = False
|
decimal_insert_validator_test = False
|
||||||
operator_test_round = 1
|
operator_test_round = 10
|
||||||
tb_insert_rows = 1000
|
tb_insert_rows = 1000
|
||||||
binary_op_with_const_test = False
|
binary_op_with_const_test = True
|
||||||
binary_op_with_col_test = False
|
binary_op_with_col_test = True
|
||||||
unary_op_test = False
|
unary_op_test = True
|
||||||
binary_op_in_where_test = True
|
binary_op_in_where_test = True
|
||||||
|
|
||||||
class DecimalTypeGeneratorConfig:
|
class DecimalTypeGeneratorConfig:
|
||||||
|
@ -1516,7 +1516,6 @@ class TDTestCase:
|
||||||
get_constant_cols_func,
|
get_constant_cols_func,
|
||||||
get_exprs_func,
|
get_exprs_func,
|
||||||
):
|
):
|
||||||
constant_cols = get_constant_cols_func()
|
|
||||||
exprs: List[DecimalColumnExpr] = get_exprs_func()
|
exprs: List[DecimalColumnExpr] = get_exprs_func()
|
||||||
if not binary_op_with_const_test:
|
if not binary_op_with_const_test:
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue