From d74834f81ebb6852338497a3e04114dc7d24d0ed Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 6 Sep 2023 14:21:30 +0800 Subject: [PATCH 1/4] fix: fix diff not support unsigned type --- include/common/tdatablock.h | 35 +++++++++++--- source/libs/function/src/builtins.c | 6 ++- source/libs/function/src/builtinsimpl.c | 62 ++++++++++++++++++++++++- 3 files changed, 93 insertions(+), 10 deletions(-) diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index 244894b59b..f2a33cc47f 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -136,32 +136,55 @@ static FORCE_INLINE void colDataSetNNULL(SColumnInfoData* pColumnInfoData, uint3 } static FORCE_INLINE void colDataSetInt8(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, int8_t* v) { - ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_TINYINT || - pColumnInfoData->info.type == TSDB_DATA_TYPE_UTINYINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_BOOL); + ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_TINYINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_BOOL); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; *(int8_t*)p = *(int8_t*)v; } static FORCE_INLINE void colDataSetInt16(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, int16_t* v) { - ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_SMALLINT || - pColumnInfoData->info.type == TSDB_DATA_TYPE_USMALLINT); + ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_SMALLINT); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; *(int16_t*)p = *(int16_t*)v; } static FORCE_INLINE void colDataSetInt32(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, int32_t* v) { - ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_INT || pColumnInfoData->info.type == TSDB_DATA_TYPE_UINT); + ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_INT); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; *(int32_t*)p = *(int32_t*)v; } static FORCE_INLINE void colDataSetInt64(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, int64_t* v) { int32_t type = pColumnInfoData->info.type; - ASSERT(type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_UBIGINT || type == TSDB_DATA_TYPE_TIMESTAMP); + ASSERT(type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_TIMESTAMP); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; *(int64_t*)p = *(int64_t*)v; } +static FORCE_INLINE void colDataSetUInt8(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, uint8_t* v) { + ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_UTINYINT); + char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; + *(uint8_t*)p = *(uint8_t*)v; +} + +static FORCE_INLINE void colDataSetUInt16(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, uint16_t* v) { + ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_USMALLINT); + char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; + *(uint16_t*)p = *(uint16_t*)v; +} + +static FORCE_INLINE void colDataSetUInt32(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, uint32_t* v) { + ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_UINT); + char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; + *(uint32_t*)p = *(uint32_t*)v; +} + +static FORCE_INLINE void colDataSetUInt64(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, uint64_t* v) { + int32_t type = pColumnInfoData->info.type; + ASSERT(type == TSDB_DATA_TYPE_UBIGINT); + char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; + *(uint64_t*)p = *(uint64_t*)v; +} + static FORCE_INLINE void colDataSetFloat(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, float* v) { ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_FLOAT); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 256123d62b..94ec5dc16a 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -1786,8 +1786,8 @@ static int32_t translateDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { } uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; - if (!IS_SIGNED_NUMERIC_TYPE(colType) && !IS_FLOAT_TYPE(colType) && TSDB_DATA_TYPE_BOOL != colType && - !IS_TIMESTAMP_TYPE(colType)) { + if (!IS_INTEGER_TYPE(colType) && !IS_FLOAT_TYPE(colType) && + TSDB_DATA_TYPE_BOOL != colType && !IS_TIMESTAMP_TYPE(colType)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } @@ -1815,6 +1815,8 @@ static int32_t translateDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { uint8_t resType; if (IS_SIGNED_NUMERIC_TYPE(colType) || IS_TIMESTAMP_TYPE(colType) || TSDB_DATA_TYPE_BOOL == colType) { resType = TSDB_DATA_TYPE_BIGINT; + } else if (IS_UNSIGNED_NUMERIC_TYPE(colType)) { + resType = TSDB_DATA_TYPE_UBIGINT; } else { resType = TSDB_DATA_TYPE_DOUBLE; } diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index bcbb3af950..e5a06b108d 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -115,8 +115,9 @@ typedef struct SDiffInfo { bool ignoreNegative; // replace the ignore with case when bool firstOutput; union { - int64_t i64; - double d64; + int64_t i64; + uint64_t u64; + double d64; } prev; int64_t prevTs; @@ -2733,6 +2734,18 @@ static int32_t doSetPrevVal(SDiffInfo* pDiffInfo, int32_t type, const char* pv, case TSDB_DATA_TYPE_DOUBLE: pDiffInfo->prev.d64 = *(double*)pv; break; + case TSDB_DATA_TYPE_UTINYINT: + pDiffInfo->prev.u64 = *(uint8_t*)pv; + break; + case TSDB_DATA_TYPE_UINT: + pDiffInfo->prev.u64 = *(uint32_t*)pv; + break; + case TSDB_DATA_TYPE_USMALLINT: + pDiffInfo->prev.u64 = *(uint16_t*)pv; + break; + case TSDB_DATA_TYPE_UBIGINT: + pDiffInfo->prev.u64 = *(uint64_t*)pv; + break; default: return TSDB_CODE_FUNC_FUNTION_PARA_TYPE; } @@ -2814,6 +2827,51 @@ static int32_t doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv, pDiffInfo->prev.d64 = v; break; } + case TSDB_DATA_TYPE_UTINYINT: { + uint8_t v = *(uint8_t*)pv; + uint64_t delta = v - pDiffInfo->prev.u64; // direct previous may be null + if (delta < 0 && pDiffInfo->ignoreNegative) { + colDataSetNull_f_s(pOutput, pos); + } else { + colDataSetUInt64(pOutput, pos, &delta); + } + pDiffInfo->prev.u64 = v; + break; + } + case TSDB_DATA_TYPE_USMALLINT: { + uint16_t v = *(uint16_t*)pv; + uint64_t delta = v - pDiffInfo->prev.u64; // direct previous may be null + if (delta < 0 && pDiffInfo->ignoreNegative) { + colDataSetNull_f_s(pOutput, pos); + } else { + colDataSetUInt64(pOutput, pos, &delta); + } + pDiffInfo->prev.u64 = v; + break; + } + case TSDB_DATA_TYPE_UINT: { + uint32_t v = *(uint32_t*)pv; + uint64_t delta = v - pDiffInfo->prev.u64; // direct previous may be null + if (delta < 0 && pDiffInfo->ignoreNegative) { + colDataSetNull_f_s(pOutput, pos); + } else { + colDataSetUInt64(pOutput, pos, &delta); + } + pDiffInfo->prev.u64 = v; + + break; + } + case TSDB_DATA_TYPE_UBIGINT: { + uint64_t v = *(uint64_t*)pv; + uint64_t delta = v - pDiffInfo->prev.i64; // direct previous may be null + if (delta < 0 && pDiffInfo->ignoreNegative) { + colDataSetNull_f_s(pOutput, pos); + } else { + colDataSetUInt64(pOutput, pos, &delta); + } + pDiffInfo->prev.u64 = v; + break; + } default: return TSDB_CODE_FUNC_FUNTION_PARA_TYPE; } From a1632cac5d3215c656ba74589dbedfc1a234ae99 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 6 Sep 2023 18:53:25 +0800 Subject: [PATCH 2/4] add test cases --- tests/system-test/2-query/diff.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/system-test/2-query/diff.py b/tests/system-test/2-query/diff.py index c6f233eefa..0a2f750f93 100644 --- a/tests/system-test/2-query/diff.py +++ b/tests/system-test/2-query/diff.py @@ -16,6 +16,9 @@ class TDTestCase: self.perfix = 'dev' self.tables = 10 + def check_result(self): + for i in range(self.rowNum): + tdSql.checkData(i, 0, 1); def run(self): tdSql.prepare() @@ -179,11 +182,6 @@ class TDTestCase: tdSql.error(f"select diff(col8) from {dbname}.stb_1") tdSql.error(f"select diff(col9) from {dbname}.stb") tdSql.error(f"select diff(col9) from {dbname}.stb_1") - tdSql.error(f"select diff(col11) from {dbname}.stb_1") - tdSql.error(f"select diff(col12) from {dbname}.stb_1") - tdSql.error(f"select diff(col13) from {dbname}.stb_1") - tdSql.error(f"select diff(col14) from {dbname}.stb_1") - tdSql.error(f"select diff(col14) from {dbname}.stb_1") tdSql.error(f"select diff(col1,col1,col1) from {dbname}.stb_1") tdSql.error(f"select diff(col1,1,col1) from {dbname}.stb_1") tdSql.error(f"select diff(col1,col1,col) from {dbname}.stb_1") @@ -217,6 +215,22 @@ class TDTestCase: tdSql.query(f"select diff(col6) from {dbname}.stb_1") tdSql.checkRows(10) + tdSql.query(f"select diff(col11) from {dbname}.stb_1") + tdSql.checkRows(10) + self.check_result() + + tdSql.query(f"select diff(col12) from {dbname}.stb_1") + tdSql.checkRows(10) + self.check_result() + + tdSql.query(f"select diff(col13) from {dbname}.stb_1") + tdSql.checkRows(10) + self.check_result() + + tdSql.query(f"select diff(col14) from {dbname}.stb_1") + tdSql.checkRows(10) + self.check_result() + tdSql.execute(f'''create table {dbname}.stb1(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned) tags(loc nchar(20))''') tdSql.execute(f"create table {dbname}.stb1_1 using {dbname}.stb tags('shanghai')") From 60d159731afa5d6736767b7445a8e237dc8278fd Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 7 Sep 2023 09:14:31 +0800 Subject: [PATCH 3/4] Revert "fix: fix diff not support unsigned type" This reverts commit 7ccf959cdc44be7c5eaa0218f84db7699c126bbb. --- include/common/tdatablock.h | 35 +++----------- source/libs/function/src/builtins.c | 6 +-- source/libs/function/src/builtinsimpl.c | 62 +------------------------ 3 files changed, 10 insertions(+), 93 deletions(-) diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index f2a33cc47f..244894b59b 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -136,55 +136,32 @@ static FORCE_INLINE void colDataSetNNULL(SColumnInfoData* pColumnInfoData, uint3 } static FORCE_INLINE void colDataSetInt8(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, int8_t* v) { - ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_TINYINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_BOOL); + ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_TINYINT || + pColumnInfoData->info.type == TSDB_DATA_TYPE_UTINYINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_BOOL); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; *(int8_t*)p = *(int8_t*)v; } static FORCE_INLINE void colDataSetInt16(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, int16_t* v) { - ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_SMALLINT); + ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_SMALLINT || + pColumnInfoData->info.type == TSDB_DATA_TYPE_USMALLINT); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; *(int16_t*)p = *(int16_t*)v; } static FORCE_INLINE void colDataSetInt32(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, int32_t* v) { - ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_INT); + ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_INT || pColumnInfoData->info.type == TSDB_DATA_TYPE_UINT); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; *(int32_t*)p = *(int32_t*)v; } static FORCE_INLINE void colDataSetInt64(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, int64_t* v) { int32_t type = pColumnInfoData->info.type; - ASSERT(type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_TIMESTAMP); + ASSERT(type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_UBIGINT || type == TSDB_DATA_TYPE_TIMESTAMP); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; *(int64_t*)p = *(int64_t*)v; } -static FORCE_INLINE void colDataSetUInt8(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, uint8_t* v) { - ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_UTINYINT); - char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; - *(uint8_t*)p = *(uint8_t*)v; -} - -static FORCE_INLINE void colDataSetUInt16(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, uint16_t* v) { - ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_USMALLINT); - char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; - *(uint16_t*)p = *(uint16_t*)v; -} - -static FORCE_INLINE void colDataSetUInt32(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, uint32_t* v) { - ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_UINT); - char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; - *(uint32_t*)p = *(uint32_t*)v; -} - -static FORCE_INLINE void colDataSetUInt64(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, uint64_t* v) { - int32_t type = pColumnInfoData->info.type; - ASSERT(type == TSDB_DATA_TYPE_UBIGINT); - char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; - *(uint64_t*)p = *(uint64_t*)v; -} - static FORCE_INLINE void colDataSetFloat(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, float* v) { ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_FLOAT); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex; diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 94ec5dc16a..256123d62b 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -1786,8 +1786,8 @@ static int32_t translateDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { } uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; - if (!IS_INTEGER_TYPE(colType) && !IS_FLOAT_TYPE(colType) && - TSDB_DATA_TYPE_BOOL != colType && !IS_TIMESTAMP_TYPE(colType)) { + if (!IS_SIGNED_NUMERIC_TYPE(colType) && !IS_FLOAT_TYPE(colType) && TSDB_DATA_TYPE_BOOL != colType && + !IS_TIMESTAMP_TYPE(colType)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } @@ -1815,8 +1815,6 @@ static int32_t translateDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { uint8_t resType; if (IS_SIGNED_NUMERIC_TYPE(colType) || IS_TIMESTAMP_TYPE(colType) || TSDB_DATA_TYPE_BOOL == colType) { resType = TSDB_DATA_TYPE_BIGINT; - } else if (IS_UNSIGNED_NUMERIC_TYPE(colType)) { - resType = TSDB_DATA_TYPE_UBIGINT; } else { resType = TSDB_DATA_TYPE_DOUBLE; } diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index e5a06b108d..bcbb3af950 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -115,9 +115,8 @@ typedef struct SDiffInfo { bool ignoreNegative; // replace the ignore with case when bool firstOutput; union { - int64_t i64; - uint64_t u64; - double d64; + int64_t i64; + double d64; } prev; int64_t prevTs; @@ -2734,18 +2733,6 @@ static int32_t doSetPrevVal(SDiffInfo* pDiffInfo, int32_t type, const char* pv, case TSDB_DATA_TYPE_DOUBLE: pDiffInfo->prev.d64 = *(double*)pv; break; - case TSDB_DATA_TYPE_UTINYINT: - pDiffInfo->prev.u64 = *(uint8_t*)pv; - break; - case TSDB_DATA_TYPE_UINT: - pDiffInfo->prev.u64 = *(uint32_t*)pv; - break; - case TSDB_DATA_TYPE_USMALLINT: - pDiffInfo->prev.u64 = *(uint16_t*)pv; - break; - case TSDB_DATA_TYPE_UBIGINT: - pDiffInfo->prev.u64 = *(uint64_t*)pv; - break; default: return TSDB_CODE_FUNC_FUNTION_PARA_TYPE; } @@ -2827,51 +2814,6 @@ static int32_t doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv, pDiffInfo->prev.d64 = v; break; } - case TSDB_DATA_TYPE_UTINYINT: { - uint8_t v = *(uint8_t*)pv; - uint64_t delta = v - pDiffInfo->prev.u64; // direct previous may be null - if (delta < 0 && pDiffInfo->ignoreNegative) { - colDataSetNull_f_s(pOutput, pos); - } else { - colDataSetUInt64(pOutput, pos, &delta); - } - pDiffInfo->prev.u64 = v; - break; - } - case TSDB_DATA_TYPE_USMALLINT: { - uint16_t v = *(uint16_t*)pv; - uint64_t delta = v - pDiffInfo->prev.u64; // direct previous may be null - if (delta < 0 && pDiffInfo->ignoreNegative) { - colDataSetNull_f_s(pOutput, pos); - } else { - colDataSetUInt64(pOutput, pos, &delta); - } - pDiffInfo->prev.u64 = v; - break; - } - case TSDB_DATA_TYPE_UINT: { - uint32_t v = *(uint32_t*)pv; - uint64_t delta = v - pDiffInfo->prev.u64; // direct previous may be null - if (delta < 0 && pDiffInfo->ignoreNegative) { - colDataSetNull_f_s(pOutput, pos); - } else { - colDataSetUInt64(pOutput, pos, &delta); - } - pDiffInfo->prev.u64 = v; - - break; - } - case TSDB_DATA_TYPE_UBIGINT: { - uint64_t v = *(uint64_t*)pv; - uint64_t delta = v - pDiffInfo->prev.i64; // direct previous may be null - if (delta < 0 && pDiffInfo->ignoreNegative) { - colDataSetNull_f_s(pOutput, pos); - } else { - colDataSetUInt64(pOutput, pos, &delta); - } - pDiffInfo->prev.u64 = v; - break; - } default: return TSDB_CODE_FUNC_FUNTION_PARA_TYPE; } From a762437100baf2b58cf3e66973911285ef27e8fc Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 7 Sep 2023 09:52:52 +0800 Subject: [PATCH 4/4] fix issue --- source/libs/function/src/builtins.c | 4 +++- source/libs/function/src/builtinsimpl.c | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 256123d62b..7b81fbbac6 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -1786,7 +1786,7 @@ static int32_t translateDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { } uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; - if (!IS_SIGNED_NUMERIC_TYPE(colType) && !IS_FLOAT_TYPE(colType) && TSDB_DATA_TYPE_BOOL != colType && + if (!IS_INTEGER_TYPE(colType) && !IS_FLOAT_TYPE(colType) && TSDB_DATA_TYPE_BOOL != colType && !IS_TIMESTAMP_TYPE(colType)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } @@ -1815,6 +1815,8 @@ static int32_t translateDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { uint8_t resType; if (IS_SIGNED_NUMERIC_TYPE(colType) || IS_TIMESTAMP_TYPE(colType) || TSDB_DATA_TYPE_BOOL == colType) { resType = TSDB_DATA_TYPE_BIGINT; + } else if (IS_UNSIGNED_NUMERIC_TYPE(colType)) { + resType = TSDB_DATA_TYPE_UBIGINT; } else { resType = TSDB_DATA_TYPE_DOUBLE; } diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index bcbb3af950..108a641c08 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -2714,16 +2714,20 @@ static int32_t doSetPrevVal(SDiffInfo* pDiffInfo, int32_t type, const char* pv, case TSDB_DATA_TYPE_BOOL: pDiffInfo->prev.i64 = *(bool*)pv ? 1 : 0; break; + case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_TINYINT: pDiffInfo->prev.i64 = *(int8_t*)pv; break; + case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_INT: pDiffInfo->prev.i64 = *(int32_t*)pv; break; + case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_SMALLINT: pDiffInfo->prev.i64 = *(int16_t*)pv; break; case TSDB_DATA_TYPE_TIMESTAMP: + case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_BIGINT: pDiffInfo->prev.i64 = *(int64_t*)pv; break; @@ -2745,6 +2749,7 @@ static int32_t doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv, int64_t ts) { pDiffInfo->prevTs = ts; switch (type) { + case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_INT: { int32_t v = *(int32_t*)pv; int64_t delta = v - pDiffInfo->prev.i64; // direct previous may be null @@ -2758,6 +2763,7 @@ static int32_t doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv, break; } case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_TINYINT: { int8_t v = *(int8_t*)pv; int64_t delta = v - pDiffInfo->prev.i64; // direct previous may be null @@ -2769,6 +2775,7 @@ static int32_t doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv, pDiffInfo->prev.i64 = v; break; } + case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_SMALLINT: { int16_t v = *(int16_t*)pv; int64_t delta = v - pDiffInfo->prev.i64; // direct previous may be null @@ -2781,6 +2788,7 @@ static int32_t doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv, break; } case TSDB_DATA_TYPE_TIMESTAMP: + case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_BIGINT: { int64_t v = *(int64_t*)pv; int64_t delta = v - pDiffInfo->prev.i64; // direct previous may be null