fix decimal tests
This commit is contained in:
parent
8500d95e6d
commit
ee77643db7
|
@ -253,15 +253,14 @@ struct SValue {
|
|||
union {
|
||||
int64_t val;
|
||||
struct {
|
||||
uint8_t *pData; // TODO wjm free or no free??? use single interface to destroy pData.
|
||||
uint8_t *pData;
|
||||
uint32_t nData;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
// TODO wjm remove type parameter maybe
|
||||
#define VALUE_GET_DATUM(pVal, type) \
|
||||
IS_VAR_DATA_TYPE(type) || type == TSDB_DATA_TYPE_DECIMAL ? (pVal)->pData : (void*)&(pVal)->val
|
||||
(IS_VAR_DATA_TYPE(type) || type == TSDB_DATA_TYPE_DECIMAL) ? (pVal)->pData : (void*)&(pVal)->val
|
||||
|
||||
#define VALUE_GET_TRIVIAL_DATUM(pVal) ((pVal)->val)
|
||||
#define VALUE_SET_TRIVIAL_DATUM(pVal, v) (pVal)->val = v
|
||||
|
@ -270,14 +269,6 @@ void valueSetDatum(SValue *pVal, int8_t type, void *pDatum, uint32_t len);
|
|||
void valueCloneDatum(SValue *pDst, const SValue *pSrc, int8_t type);
|
||||
void valueClearDatum(SValue *pVal, int8_t type);
|
||||
|
||||
//uint8_t* valueGetVarDatum(const SValue *pVal);
|
||||
//uint32_t valueGetVarNDatum(const SValue *pVal);
|
||||
//void valueSetVarDatum(SValue *pVal, uint8_t *pData, uint32_t nData);
|
||||
|
||||
//DecimalWord* valueGetDecimalDatum(const SValue *pVal);
|
||||
//uint32_t valueGetDecimalWordNum(const SValue *pVal);
|
||||
//void valueSetDecimalDatum(SValue *pVal, DecimalWord *words, int32_t wordNum);
|
||||
|
||||
#define TD_MAX_PK_COLS 2
|
||||
struct SRowKey {
|
||||
TSKEY ts;
|
||||
|
|
|
@ -705,7 +705,7 @@ typedef struct {
|
|||
} SMonitorParas;
|
||||
|
||||
typedef struct {
|
||||
STypeMod typeMod; // TODO wjm copy it with a struct, not it's internal members
|
||||
STypeMod typeMod;
|
||||
} SExtSchema;
|
||||
|
||||
bool hasExtSchema(const SExtSchema* pExtSchema);
|
||||
|
|
|
@ -114,7 +114,7 @@ typedef struct SDecimalOps {
|
|||
} SDecimalOps;
|
||||
|
||||
// all these ops only used for comparing decimal types with same scale
|
||||
SDecimalOps* getDecimalOps(int8_t dataType);
|
||||
const SDecimalOps* getDecimalOps(int8_t dataType);
|
||||
|
||||
#if 0
|
||||
__int128 decimal128ToInt128(const Decimal128* pDec);
|
||||
|
|
|
@ -2859,7 +2859,7 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq2** ppReq, const SSDataBlock* pDat
|
|||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_DECIMAL:
|
||||
case TSDB_DATA_TYPE_DECIMAL: // TODO wjm
|
||||
case TSDB_DATA_TYPE_BLOB:
|
||||
case TSDB_DATA_TYPE_JSON:
|
||||
case TSDB_DATA_TYPE_MEDIUMBLOB:
|
||||
|
|
|
@ -4280,8 +4280,8 @@ static FORCE_INLINE void tColDataCalcSMADecimal128Type(SColData* pColData, SColu
|
|||
pAggs->numOfNull = 0;
|
||||
pAggs->colId |= 0x80000000; // TODO wjm define it
|
||||
|
||||
Decimal128 *pVal = NULL;
|
||||
SDecimalOps* pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL);
|
||||
Decimal128 *pVal = NULL;
|
||||
const SDecimalOps *pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL);
|
||||
if (HAS_VALUE == pColData->flag) {
|
||||
for (int32_t iVal = 0; iVal < pColData->nVal; ++iVal) {
|
||||
pVal = ((Decimal128*)pColData->pData) + iVal;
|
||||
|
@ -4803,7 +4803,7 @@ void valueCloneDatum(SValue *pDst, const SValue *pSrc, int8_t type) {
|
|||
}
|
||||
void valueClearDatum(SValue *pVal, int8_t type) {
|
||||
if (IS_VAR_DATA_TYPE(type) || type == TSDB_DATA_TYPE_DECIMAL) {
|
||||
pVal->pData = NULL;
|
||||
taosMemoryFreeClear(pVal->pData);
|
||||
pVal->nData = 0;
|
||||
} else {
|
||||
pVal->val = 0;
|
||||
|
|
|
@ -678,7 +678,6 @@ int32_t metaAddTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, ST
|
|||
TAOS_RETURN(code);
|
||||
}
|
||||
code = addTableExtSchema(pEntry, pColumn, pSchema->nCols, &extSchema);
|
||||
// TODO wjm update extSchema, client set typeMod in add request.
|
||||
if (code) {
|
||||
metaError("vgId:%d, %s failed to add ext schema at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode),
|
||||
__func__, __FILE__, __LINE__, tstrerror(code), version);
|
||||
|
|
|
@ -414,8 +414,10 @@ static int32_t tsdbCacheSerializeV0(char const *value, SLastCol *pLastCol) {
|
|||
}
|
||||
return sizeof(SLastColV0) + pLastCol->colVal.value.nData;
|
||||
} else if (pLastCol->colVal.value.type == TSDB_DATA_TYPE_DECIMAL) {
|
||||
memcpy(&pLastColV0[1], pLastCol->colVal.value.pData, pLastCol->colVal.value.nData);
|
||||
pLastColV0->colVal.value.nData = pLastCol->colVal.value.nData;
|
||||
if (pLastCol->colVal.value.nData > 0) {
|
||||
memcpy(&pLastColV0[1], pLastCol->colVal.value.pData, pLastCol->colVal.value.nData);
|
||||
}
|
||||
return sizeof(SLastColV0) + pLastCol->colVal.value.nData;
|
||||
} else {
|
||||
pLastColV0->colVal.value.val = pLastCol->colVal.value.val;
|
||||
|
@ -834,10 +836,12 @@ static int32_t tsdbCacheReallocSLastCol(SLastCol *pCol, size_t *pCharge) {
|
|||
}
|
||||
|
||||
if (pCol->colVal.value.type == TSDB_DATA_TYPE_DECIMAL) {
|
||||
void* p = taosMemoryMalloc(pCol->colVal.value.nData);
|
||||
if (!p) TAOS_CHECK_EXIT(terrno);
|
||||
(void)memcpy(p, pCol->colVal.value.pData, pCol->colVal.value.nData);
|
||||
pCol->colVal.value.pData = p;
|
||||
if (pCol->colVal.value.nData > 0) {
|
||||
void *p = taosMemoryMalloc(pCol->colVal.value.nData);
|
||||
if (!p) TAOS_CHECK_EXIT(terrno);
|
||||
(void)memcpy(p, pCol->colVal.value.pData, pCol->colVal.value.nData);
|
||||
pCol->colVal.value.pData = p;
|
||||
}
|
||||
charge += pCol->colVal.value.nData;
|
||||
}
|
||||
|
||||
|
@ -867,7 +871,8 @@ void tsdbCacheFreeSLastColItem(void *pItem) {
|
|||
}
|
||||
}
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pCol->colVal.value.type) && pCol->colVal.value.pData) {
|
||||
if ((IS_VAR_DATA_TYPE(pCol->colVal.value.type) || pCol->colVal.value.type == TSDB_DATA_TYPE_DECIMAL) &&
|
||||
pCol->colVal.value.pData) {
|
||||
taosMemoryFree(pCol->colVal.value.pData);
|
||||
}
|
||||
}
|
||||
|
@ -889,7 +894,8 @@ static void tsdbCacheDeleter(const void *key, size_t klen, void *value, void *ud
|
|||
}
|
||||
}
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pLastCol->colVal.value.type) /* && pLastCol->colVal.value.nData > 0*/) {
|
||||
if (IS_VAR_DATA_TYPE(pLastCol->colVal.value.type) ||
|
||||
pLastCol->colVal.value.type == TSDB_DATA_TYPE_DECIMAL /* && pLastCol->colVal.value.nData > 0*/) {
|
||||
taosMemoryFree(pLastCol->colVal.value.pData);
|
||||
}
|
||||
|
||||
|
|
|
@ -545,7 +545,7 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
|
|||
}
|
||||
}
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
if (IS_VAR_DATA_TYPE(pCol->type) || pCol->type == TSDB_DATA_TYPE_DECIMAL) {
|
||||
p.colVal.value.pData = taosMemoryCalloc(pCol->bytes, sizeof(char));
|
||||
TSDB_CHECK_NULL(p.colVal.value.pData, code, lino, _end, terrno);
|
||||
}
|
||||
|
@ -630,7 +630,7 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
|
|||
goto _end;
|
||||
}
|
||||
|
||||
if (!IS_VAR_DATA_TYPE(pColVal->colVal.value.type)) {
|
||||
if (!IS_VAR_DATA_TYPE(pColVal->colVal.value.type) && pColVal->colVal.value.type != TSDB_DATA_TYPE_DECIMAL) {
|
||||
p->colVal = pColVal->colVal;
|
||||
} else {
|
||||
if (COL_VAL_IS_VALUE(&pColVal->colVal)) {
|
||||
|
|
|
@ -64,7 +64,7 @@ int32_t tCreateSttBlockLoadInfo(STSchema *pSchema, int16_t *colList, int32_t num
|
|||
|
||||
static void freeItem(void *pValue) {
|
||||
SValue *p = (SValue *)pValue;
|
||||
if (IS_VAR_DATA_TYPE(p->type)) {
|
||||
if (IS_VAR_DATA_TYPE(p->type) || p->type == TSDB_DATA_TYPE_DECIMAL) {
|
||||
taosMemoryFree(p->pData);
|
||||
}
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ static int32_t extractSttBlockInfo(SLDataIter *pIter, const TSttBlkArray *pArray
|
|||
}
|
||||
|
||||
static int32_t tValueDupPayload(SValue *pVal) {
|
||||
if (IS_VAR_DATA_TYPE(pVal->type)) {
|
||||
if (IS_VAR_DATA_TYPE(pVal->type) || pVal->type == TSDB_DATA_TYPE_DECIMAL) {
|
||||
char *p = (char *)pVal->pData;
|
||||
char *pBuf = taosMemoryMalloc(pVal->nData);
|
||||
if (pBuf == NULL) {
|
||||
|
|
|
@ -777,7 +777,8 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
|||
}
|
||||
|
||||
tsdbRowGetColVal(pRow, pTSchema, jCol++, pColVal);
|
||||
if ((!COL_VAL_IS_NONE(pColVal)) && (!COL_VAL_IS_NULL(pColVal)) && IS_VAR_DATA_TYPE(pColVal->value.type)) {
|
||||
bool usepData = IS_VAR_DATA_TYPE(pColVal->value.type) || pColVal->value.type == TSDB_DATA_TYPE_DECIMAL;
|
||||
if ((!COL_VAL_IS_NONE(pColVal)) && (!COL_VAL_IS_NULL(pColVal)) && usepData) {
|
||||
uint8_t *pVal = pColVal->value.pData;
|
||||
|
||||
pColVal->value.pData = NULL;
|
||||
|
@ -820,7 +821,7 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
|||
|
||||
if (key.version > pMerger->version) {
|
||||
if (!COL_VAL_IS_NONE(pColVal)) {
|
||||
if (IS_VAR_DATA_TYPE(pColVal->value.type)) {
|
||||
if (IS_VAR_DATA_TYPE(pColVal->value.type) || pColVal->value.type == TSDB_DATA_TYPE_DECIMAL) {
|
||||
SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
|
||||
if (!pTColVal) return terrno;
|
||||
if (!COL_VAL_IS_NULL(pColVal)) {
|
||||
|
@ -843,7 +844,8 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
|||
} else if (key.version < pMerger->version) {
|
||||
SColVal *tColVal = (SColVal *)taosArrayGet(pMerger->pArray, iCol);
|
||||
if (COL_VAL_IS_NONE(tColVal) && !COL_VAL_IS_NONE(pColVal)) {
|
||||
if ((!COL_VAL_IS_NULL(pColVal)) && IS_VAR_DATA_TYPE(pColVal->value.type)) {
|
||||
bool usepData = IS_VAR_DATA_TYPE(pColVal->value.type) || pColVal->value.type == TSDB_DATA_TYPE_DECIMAL;
|
||||
if ((!COL_VAL_IS_NULL(pColVal)) && usepData) {
|
||||
code = tRealloc(&tColVal->value.pData, pColVal->value.nData);
|
||||
if (code) return code;
|
||||
|
||||
|
@ -879,7 +881,7 @@ int32_t tsdbRowMergerInit(SRowMerger *pMerger, STSchema *pSchema) {
|
|||
void tsdbRowMergerClear(SRowMerger *pMerger) {
|
||||
for (int32_t iCol = 1; iCol < pMerger->pTSchema->numOfCols; iCol++) {
|
||||
SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
|
||||
if (IS_VAR_DATA_TYPE(pTColVal->value.type)) {
|
||||
if (IS_VAR_DATA_TYPE(pTColVal->value.type) || pTColVal->value.type == TSDB_DATA_TYPE_DECIMAL) {
|
||||
tFree(pTColVal->value.pData);
|
||||
}
|
||||
}
|
||||
|
@ -891,7 +893,7 @@ void tsdbRowMergerCleanup(SRowMerger *pMerger) {
|
|||
int32_t numOfCols = taosArrayGetSize(pMerger->pArray);
|
||||
for (int32_t iCol = 1; iCol < numOfCols; iCol++) {
|
||||
SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
|
||||
if (IS_VAR_DATA_TYPE(pTColVal->value.type)) {
|
||||
if (IS_VAR_DATA_TYPE(pTColVal->value.type) || pTColVal->value.type == TSDB_DATA_TYPE_DECIMAL) {
|
||||
tFree(pTColVal->value.pData);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ UInt256 uInt256RightShift(const UInt256* pLeft, int32_t shift);
|
|||
extern const UInt256 uInt256Zero;
|
||||
extern const UInt256 uInt256One;
|
||||
|
||||
Int256 makeInt256(Int128 high, UInt128 low);// TODO wjm all params should be high then low
|
||||
Int256 makeInt256(Int128 high, UInt128 low);
|
||||
Int128 int256Hi(const Int256* pUint256);
|
||||
UInt128 int256Lo(const Int256* pUint256);
|
||||
Int256 int256Abs(const Int256* pInt256);
|
||||
|
|
|
@ -300,7 +300,7 @@ int32_t decimal128ToDataVal(Decimal128* dec, SValue* pVal) {
|
|||
#define DECIMAL64_SIGN(pDec) (1 | (DECIMAL64_GET_VALUE(pDec) >> 63))
|
||||
|
||||
static void decimal64GetWhole(const DecimalType* pDec, int8_t scale, DecimalType* pWhole) {
|
||||
SDecimalOps* pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL64);
|
||||
const SDecimalOps* pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL64);
|
||||
DECIMAL64_CLONE(pWhole, pDec);
|
||||
Decimal64 scaleMul = SCALE_MULTIPLIER_64[scale];
|
||||
pOps->divide(pWhole, &scaleMul, 1, NULL);
|
||||
|
@ -308,7 +308,7 @@ static void decimal64GetWhole(const DecimalType* pDec, int8_t scale, DecimalType
|
|||
}
|
||||
|
||||
static void decimal64GetFrac(const DecimalType* pDec, int8_t scale, DecimalType* pFrac) {
|
||||
SDecimalOps* pOps = getDecimalOpsImp(DECIMAL_64);
|
||||
const SDecimalOps* pOps = getDecimalOpsImp(DECIMAL_64);
|
||||
DECIMAL64_CLONE(pFrac, pDec);
|
||||
Decimal64 scaleMul = SCALE_MULTIPLIER_64[scale];
|
||||
pOps->mod(pFrac, &scaleMul, 1);
|
||||
|
@ -380,13 +380,10 @@ static SDecimalOps* getDecimalOpsImp(DecimalInternalType t) {
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
// TODO wjm const??
|
||||
SDecimalOps* getDecimalOps(int8_t dataType) { return getDecimalOpsImp(DECIMAL_GET_INTERNAL_TYPE(dataType)); }
|
||||
const SDecimalOps* getDecimalOps(int8_t dataType) { return getDecimalOpsImp(DECIMAL_GET_INTERNAL_TYPE(dataType)); }
|
||||
|
||||
void makeDecimal64(Decimal64* pDec64, int64_t w) { DECIMAL64_SET_VALUE(pDec64, w); }
|
||||
|
||||
// TODO wjm handle overflow problem of DecimalWord
|
||||
// it's impossible that pDec == INT64_MIN, only 18 digits can be accepted.
|
||||
void decimal64Negate(DecimalType* pInt) {
|
||||
Decimal64* pDec = pInt;
|
||||
DECIMAL64_SET_VALUE(pDec, -DECIMAL64_GET_VALUE(pDec));
|
||||
|
@ -452,7 +449,6 @@ bool decimal64Eq(const DecimalType* pLeft, const DecimalType* pRight, uint8_t ri
|
|||
}
|
||||
int32_t decimal64ToStr(const DecimalType* pInt, uint8_t scale, char* pBuf, int32_t bufLen) {
|
||||
Decimal whole = {0}, frac = {0};
|
||||
DecimalWord zero = 0; // TODO wjm remove zero, use SIGN
|
||||
int32_t pos = 0;
|
||||
|
||||
if (DECIMAL64_SIGN((Decimal64*)pInt) == -1) {
|
||||
|
@ -514,7 +510,7 @@ static const Decimal128 SCALE_MULTIPLIER_128[TSDB_DECIMAL128_MAX_PRECISION + 1]
|
|||
DEFINE_DECIMAL128(4003012203950112768ULL, 542101086242752LL),
|
||||
DEFINE_DECIMAL128(3136633892082024448ULL, 5421010862427522LL),
|
||||
DEFINE_DECIMAL128(12919594847110692864ULL, 54210108624275221LL),
|
||||
DEFINE_DECIMAL128(68739955140067328ULL, 542101086242752217LL), // TODO wjm TEST it
|
||||
DEFINE_DECIMAL128(68739955140067328ULL, 542101086242752217LL),
|
||||
DEFINE_DECIMAL128(687399551400673280ULL, 5421010862427522170LL),
|
||||
};
|
||||
|
||||
|
@ -566,7 +562,7 @@ static void decimal128Negate(DecimalType* pWord) {
|
|||
Decimal128* pDec = (Decimal128*)pWord;
|
||||
uint64_t lo = ~DECIMAL128_LOW_WORD(pDec) + 1;
|
||||
int64_t hi = ~DECIMAL128_HIGH_WORD(pDec);
|
||||
if (lo == 0) hi = SAFE_INT64_ADD(hi, 1); // TODO wjm test if overflow?
|
||||
if (lo == 0) hi = SAFE_INT64_ADD(hi, 1);
|
||||
makeDecimal128(pDec, hi, lo);
|
||||
}
|
||||
|
||||
|
@ -576,7 +572,6 @@ static void decimal128Abs(DecimalType* pWord) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO wjm put it out of decimal128 functions
|
||||
#define DECIMAL128_CHECK_RIGHT_WORD_NUM(rightWordNum, pTarget, rightDec, pWord) \
|
||||
if (rightWordNum != WORD_NUM(Decimal128)) { \
|
||||
Decimal64 d64 = {0}; \
|
||||
|
@ -615,7 +610,7 @@ static void decimal128Multiply(DecimalType* pLeft, const DecimalType* pRight, ui
|
|||
bool negate = DECIMAL128_SIGN(pLeftDec) != DECIMAL128_SIGN(pRightDec);
|
||||
Decimal128 x = *pLeftDec, y = *pRightDec;
|
||||
decimal128Abs(&x);
|
||||
decimal128Abs(&y); // TODO wjm use too much abs, optimize it.
|
||||
decimal128Abs(&y);
|
||||
|
||||
UInt128 res = {0}, tmp = {0};
|
||||
makeUInt128(&res, DECIMAL128_HIGH_WORD(&x), DECIMAL128_LOW_WORD(&x));
|
||||
|
@ -626,7 +621,6 @@ static void decimal128Multiply(DecimalType* pLeft, const DecimalType* pRight, ui
|
|||
}
|
||||
|
||||
static bool decimal128Lt(const DecimalType* pLeft, const DecimalType* pRight, uint8_t rightWordNum) {
|
||||
// TODO wjm pRightDec use const
|
||||
Decimal128 *pLeftDec = (Decimal128*)pLeft, *pRightDec = (Decimal128*)pRight;
|
||||
Decimal128 right = {0};
|
||||
DECIMAL128_CHECK_RIGHT_WORD_NUM(rightWordNum, pRightDec, right, pRight);
|
||||
|
@ -745,7 +739,6 @@ static int32_t decimal128ToStr(const DecimalType* pInt, uint8_t scale, char* pBu
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
// TODO wjm refine this interface
|
||||
int32_t decimalToStr(const DecimalType* pDec, int8_t dataType, int8_t precision, int8_t scale, char* pBuf,
|
||||
int32_t bufLen) {
|
||||
pBuf[0] = '\0';
|
||||
|
@ -1285,25 +1278,25 @@ static int32_t decimal64FromUint64(DecimalType* pDec, uint8_t prec, uint8_t scal
|
|||
static int32_t decimal64FromDouble(DecimalType* pDec, uint8_t prec, uint8_t scale, double val) {
|
||||
double unscaled = val * getDoubleScaleMultiplier(scale);
|
||||
if (isnan(unscaled)) {
|
||||
goto _OVERFLOW;
|
||||
goto __OVERFLOW__;
|
||||
}
|
||||
unscaled = round(unscaled);
|
||||
|
||||
bool negative = unscaled < 0 ? true : false;
|
||||
double abs = TABS(unscaled);
|
||||
if (abs > ldexp(1.0, 63) - 1) {
|
||||
goto _OVERFLOW;
|
||||
goto __OVERFLOW__;
|
||||
}
|
||||
|
||||
uint64_t result = (uint64_t)abs;
|
||||
makeDecimal64(pDec, result);
|
||||
Decimal64 max = {0};
|
||||
DECIMAL64_GET_MAX(prec, &max);
|
||||
if (decimal64Gt(pDec, &max, WORD_NUM(Decimal64))) goto _OVERFLOW;
|
||||
if (decimal64Gt(pDec, &max, WORD_NUM(Decimal64))) goto __OVERFLOW__;
|
||||
if (negative) decimal64Negate(pDec);
|
||||
return 0;
|
||||
|
||||
_OVERFLOW:
|
||||
__OVERFLOW__:
|
||||
makeDecimal64(pDec, 0);
|
||||
return TSDB_CODE_DECIMAL_OVERFLOW;
|
||||
}
|
||||
|
@ -1408,25 +1401,25 @@ static int32_t decimal128FromUint64(DecimalType* pDec, uint8_t prec, uint8_t sca
|
|||
static int32_t decimal128FromDouble(DecimalType* pDec, uint8_t prec, uint8_t scale, double val) {
|
||||
double unscaled = val * getDoubleScaleMultiplier(scale);
|
||||
if (isnan(unscaled)) {
|
||||
goto _OVERFLOW;
|
||||
goto __OVERFLOW__;
|
||||
}
|
||||
unscaled = round(unscaled);
|
||||
|
||||
bool negative = unscaled < 0 ? true : false;
|
||||
double abs = TABS(unscaled);
|
||||
if (abs > ldexp(1.0, 127) - 1) {
|
||||
goto _OVERFLOW;
|
||||
goto __OVERFLOW__;
|
||||
}
|
||||
|
||||
uint64_t hi = (uint64_t)ldexp(abs, -64), lo = (uint64_t)(abs - ldexp((double)hi, 64));
|
||||
makeDecimal128(pDec, hi, lo);
|
||||
Decimal128 max = {0};
|
||||
DECIMAL128_GET_MAX(prec, &max);
|
||||
if (decimal128Gt(pDec, &max, WORD_NUM(Decimal128))) goto _OVERFLOW;
|
||||
if (decimal128Gt(pDec, &max, WORD_NUM(Decimal128))) goto __OVERFLOW__;
|
||||
if (negative) decimal128Negate(pDec);
|
||||
return 0;
|
||||
|
||||
_OVERFLOW:
|
||||
__OVERFLOW__:
|
||||
*(Decimal128*)pDec = decimal128Zero;
|
||||
return TSDB_CODE_DECIMAL_OVERFLOW;
|
||||
}
|
||||
|
@ -1468,8 +1461,7 @@ static int32_t decimal128FromDecimal128(DecimalType* pDec, uint8_t prec, uint8_t
|
|||
}
|
||||
|
||||
#define CONVERT_TO_DECIMAL(pData, pInputType, pOut, pOutType, decimal) \
|
||||
({ \
|
||||
int32_t code = 0; \
|
||||
do { \
|
||||
int64_t val = 0; \
|
||||
uint64_t uval = 0; \
|
||||
double dval = 0; \
|
||||
|
@ -1539,19 +1531,17 @@ static int32_t decimal128FromDecimal128(DecimalType* pDec, uint8_t prec, uint8_t
|
|||
code = TSDB_CODE_OPS_NOT_SUPPORT; \
|
||||
break; \
|
||||
} \
|
||||
code; \
|
||||
})
|
||||
} while (0)
|
||||
|
||||
int32_t convertToDecimal(const void* pData, const SDataType* pInputType, void* pOut, const SDataType* pOutType) {
|
||||
// if (pInputType->type == pOutType->type) return 0;
|
||||
int32_t code = 0;
|
||||
|
||||
switch (pOutType->type) {
|
||||
case TSDB_DATA_TYPE_DECIMAL64: {
|
||||
code = CONVERT_TO_DECIMAL(pData, pInputType, pOut, pOutType, decimal64);
|
||||
CONVERT_TO_DECIMAL(pData, pInputType, pOut, pOutType, decimal64);
|
||||
} break;
|
||||
case TSDB_DATA_TYPE_DECIMAL: {
|
||||
code = CONVERT_TO_DECIMAL(pData, pInputType, pOut, pOutType, decimal128);
|
||||
CONVERT_TO_DECIMAL(pData, pInputType, pOut, pOutType, decimal128);
|
||||
} break;
|
||||
default:
|
||||
code = TSDB_CODE_INTERNAL_ERROR;
|
||||
|
@ -1702,7 +1692,6 @@ int32_t decimal64FromStr(const char* str, int32_t len, uint8_t expectPrecision,
|
|||
return code;
|
||||
}
|
||||
|
||||
// TODO wjm add round param
|
||||
static void decimal128ScaleDown(Decimal128* pDec, uint8_t scaleDown, bool round) {
|
||||
if (scaleDown > 0) {
|
||||
Decimal128 divisor = SCALE_MULTIPLIER_128[scaleDown], remainder = {0};
|
||||
|
|
|
@ -11,5 +11,5 @@ target_include_directories(
|
|||
)
|
||||
target_link_libraries(
|
||||
wideInteger
|
||||
PUBLIC stdc++
|
||||
)
|
||||
PUBLIC
|
||||
)
|
||||
|
|
|
@ -264,7 +264,6 @@ int32_t buildSubmitReqFromBlock(SDataInserterHandle* pInserter, SSubmitReq2** pp
|
|||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_DECIMAL:// TODO wjm what are you doing here?
|
||||
case TSDB_DATA_TYPE_BLOB:
|
||||
case TSDB_DATA_TYPE_JSON:
|
||||
case TSDB_DATA_TYPE_MEDIUMBLOB:
|
||||
|
|
|
@ -49,7 +49,6 @@ typedef struct SSumRes {
|
|||
|
||||
typedef struct SDecimalSumRes {
|
||||
Decimal128 sum;
|
||||
// TODO wjm use same struct for the following four fields as SSumRes
|
||||
int16_t type;
|
||||
int64_t prevTs;
|
||||
bool isPrevTsSet;
|
||||
|
|
|
@ -675,13 +675,13 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc, int32_t* nElems)
|
|||
code = saveRelatedTupleTag(pCtx, pInput, tval);
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_DECIMAL64) {
|
||||
SDecimalOps* pOps = getDecimalOps(type);
|
||||
const SDecimalOps* pOps = getDecimalOps(type);
|
||||
if (pOps->lt(&pBuf->v, tval, WORD_NUM(Decimal64)) ^ isMinFunc) {
|
||||
DECIMAL64_SET_VALUE((Decimal64*)&pBuf->v, *(int64_t*)tval);
|
||||
code =saveRelatedTupleTag(pCtx, pInput, tval);
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_DECIMAL) {
|
||||
SDecimalOps* pOps = getDecimalOps(type);
|
||||
const SDecimalOps* pOps = getDecimalOps(type);
|
||||
if (pOps->lt(pBuf->str, tval, WORD_NUM(Decimal128)) ^ isMinFunc) {
|
||||
DECIMAL128_CLONE((Decimal128*)pBuf->str, (Decimal128*)tval);
|
||||
code =saveRelatedTupleTag(pCtx, pInput, tval);
|
||||
|
|
|
@ -1594,7 +1594,7 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql,
|
|||
VALUE_SET_TRIVIAL_DATUM(&pVal->value, v);
|
||||
} else if ((pToken->type == TK_NK_HEX || pToken->type == TK_NK_BIN) &&
|
||||
(TSDB_CODE_SUCCESS ==
|
||||
toDoubleEx(pToken->z, pToken->n, pToken->type, (double*)&VALUE_GET_TRIVIAL_DATUM(&pVal->value)))) { // TODO wjm use valueGetDatum instead
|
||||
toDoubleEx(pToken->z, pToken->n, pToken->type, (double*)&VALUE_GET_TRIVIAL_DATUM(&pVal->value)))) {
|
||||
int8_t v = *(double*)&VALUE_GET_TRIVIAL_DATUM(&pVal->value) == 0 ? FALSE_VALUE : TRUE_VALUE;
|
||||
valueSetDatum(&pVal->value, TSDB_DATA_TYPE_BOOL, &v, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
|
||||
} else {
|
||||
|
|
|
@ -9540,7 +9540,7 @@ static int32_t checkTableColsSchema(STranslateContext* pCxt, SHashObj* pHash, in
|
|||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && isAggrRollup && 0 != colIndex) { // TODO wjm, test is agg rollup
|
||||
if (TSDB_CODE_SUCCESS == code && isAggrRollup && 0 != colIndex) {
|
||||
if (pCol->dataType.type != TSDB_DATA_TYPE_FLOAT && pCol->dataType.type != TSDB_DATA_TYPE_DOUBLE) {
|
||||
code =
|
||||
generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_COLUMN,
|
||||
|
|
|
@ -5247,7 +5247,11 @@ static int32_t fltSclProcessCNF(SFilterInfo *pInfo, SArray *sclOpListCNF, SArray
|
|||
if (NULL == points) {
|
||||
FLT_ERR_RET(terrno);
|
||||
}
|
||||
FLT_ERR_RET(fltSclBuildRangePoints(sclOper, points));
|
||||
int32_t code = fltSclBuildRangePoints(sclOper, points);
|
||||
if (code != 0) {
|
||||
taosArrayDestroy(points);
|
||||
FLT_ERR_RET(code);
|
||||
}
|
||||
if (taosArrayGetSize(colRange->points) != 0) {
|
||||
SArray *merged = taosArrayInit(4, sizeof(SFltSclPoint));
|
||||
if (NULL == merged) {
|
||||
|
@ -5388,6 +5392,7 @@ _return:
|
|||
nodesDestroyNode((SNode *)colRange->colNode);
|
||||
taosArrayDestroy(colRange->points);
|
||||
}
|
||||
taosArrayDestroy(colRangeList);
|
||||
taosArrayDestroy(sclOpList);
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -1105,7 +1105,7 @@ STypeMod getConvertTypeMod(int32_t type, const SColumnInfo* pCol1, const SColumn
|
|||
} else if (pCol2 && IS_DECIMAL_TYPE(pCol2->type) && !IS_DECIMAL_TYPE(pCol1->type)) {
|
||||
return decimalCalcTypeMod(GET_DEICMAL_MAX_PRECISION(type), pCol2->scale);
|
||||
} else if (IS_DECIMAL_TYPE(pCol1->type) && pCol2 && IS_DECIMAL_TYPE(pCol2->type)) {
|
||||
return decimalCalcTypeMod(GET_DEICMAL_MAX_PRECISION(type), MAX(pCol1->scale, pCol2->scale));
|
||||
return decimalCalcTypeMod(GET_DEICMAL_MAX_PRECISION(type), TMAX(pCol1->scale, pCol2->scale));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
@ -2315,7 +2315,7 @@ static int32_t vectorMathUnaryOpForDecimal(SScalarParam *pCol, SScalarParam *pOu
|
|||
EOperatorType op) {
|
||||
int32_t code = 0;
|
||||
SColumnInfoData *pOutputCol = pOut->columnData;
|
||||
void *pDec = pOutputCol->pData;
|
||||
char *pDec = pOutputCol->pData;
|
||||
for (; i < pCol->numOfRows && i >= 0; i += step, pDec += tDataTypes[pOutputCol->info.type].bytes) {
|
||||
if (IS_HELPER_NULL(pCol->columnData, i)) {
|
||||
colDataSetNULL(pOutputCol, i);
|
||||
|
|
|
@ -1057,28 +1057,28 @@ int32_t compareDecimal128(const void* pleft, const void* pright) {
|
|||
}
|
||||
|
||||
int32_t compareDecimal64SameScale(const void* pleft, const void* pright) {
|
||||
SDecimalOps* pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL64);
|
||||
const SDecimalOps* pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL64);
|
||||
if (pOps->gt(pleft, pright, WORD_NUM(Decimal64))) return 1;
|
||||
if (pOps->lt(pleft, pright, WORD_NUM(Decimal64))) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t compareDecimal64SameScaleDesc(const void* pLeft, const void* pRight) {
|
||||
SDecimalOps* pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL64);
|
||||
const SDecimalOps* pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL64);
|
||||
if (pOps->lt(pLeft, pRight, WORD_NUM(Decimal64))) return 1;
|
||||
if (pOps->gt(pLeft, pRight, WORD_NUM(Decimal64))) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t compareDecimal128SameScale(const void* pleft, const void* pright) {
|
||||
SDecimalOps* pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL);
|
||||
const SDecimalOps* pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL);
|
||||
if (pOps->gt(pleft, pright, WORD_NUM(Decimal))) return 1;
|
||||
if (pOps->lt(pleft, pright, WORD_NUM(Decimal))) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t compareDecimal128SameScaleDesc(const void* pLeft, const void* pRight) {
|
||||
SDecimalOps* pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL);
|
||||
const SDecimalOps* pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL);
|
||||
if (pOps->lt(pLeft, pRight, WORD_NUM(Decimal))) return 1;
|
||||
if (pOps->gt(pLeft, pRight, WORD_NUM(Decimal))) return -1;
|
||||
return 0;
|
||||
|
|
|
@ -317,6 +317,10 @@
|
|||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/tsma2.py -Q 2
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/tsma2.py -Q 3
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/tsma2.py -Q 4
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/decimal.py -Q 4
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/decimal.py -Q 3
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/decimal.py -Q 2
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/decimal.py -Q 1
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/tbnameIn.py
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/tbnameIn.py -R
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/tbnameIn.py -Q 2
|
||||
|
|
|
@ -859,6 +859,7 @@ class TableInserter:
|
|||
def insert(self, rows: int, start_ts: int, step: int, flush_database: bool = False):
|
||||
pre_insert = f"insert into {self.dbName}.{self.tbName} values"
|
||||
sql = pre_insert
|
||||
t = datetime.now()
|
||||
for i in range(rows):
|
||||
sql += f"({start_ts + i * step}"
|
||||
for column in self.columns:
|
||||
|
@ -872,12 +873,17 @@ class TableInserter:
|
|||
if flush_database and local_flush_database:
|
||||
self.conn.execute(f"flush database {self.dbName}", queryTimes=1)
|
||||
self.conn.execute(sql, queryTimes=1)
|
||||
t1 = datetime.now()
|
||||
if (t1 - t).seconds > 1:
|
||||
TaosShell().query(f"select last(c1), last(c2) from {self.dbName}.{self.tbName}")
|
||||
t = t1
|
||||
sql = pre_insert
|
||||
if len(sql) > len(pre_insert):
|
||||
# tdLog.debug(f"insert into with sql{sql}")
|
||||
if flush_database:
|
||||
self.conn.execute(f"flush database {self.dbName}", queryTimes=1)
|
||||
self.conn.execute(sql, queryTimes=1)
|
||||
TaosShell().query(f"select last(c1), last(c2) from {self.dbName}.{self.tbName}")
|
||||
|
||||
class DecimalCastTypeGenerator:
|
||||
def __init__(self, input_type: DataType):
|
||||
|
@ -1844,7 +1850,6 @@ class TDTestCase:
|
|||
def test_decimal_ddl(self):
|
||||
tdSql.execute("create database test cachemodel 'both'", queryTimes=1)
|
||||
self.test_decimal_column_ddl()
|
||||
## TODO test decimal column for tmq
|
||||
|
||||
def test_decimal_and_stream(self):
|
||||
create_stream = f"CREATE STREAM {self.stream_name} FILL_HISTORY 1 INTO {self.db_name}.{self.stream_out_stb} AS SELECT _wstart, count(c1), avg(c2), sum(c3) FROM {self.db_name}.{self.stable_name} INTERVAL(10s)"
|
||||
|
|
Loading…
Reference in New Issue