From 148b90348761ea333c92ebde76937cd5ff037deb Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 10 Nov 2021 17:35:59 +0800 Subject: [PATCH] [TD-10932]fix double to int64 issue --- src/inc/ttype.h | 41 +++++++++++++++++++++++++++++++++++++++ src/query/src/qAggMain.c | 11 +++++++---- src/query/src/qExecutor.c | 10 ++++------ 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/inc/ttype.h b/src/inc/ttype.h index 3f1606e957..095b593ab7 100644 --- a/src/inc/ttype.h +++ b/src/inc/ttype.h @@ -50,6 +50,47 @@ typedef struct { #define TSDB_DATA_TYPE_POINTER_ARRAY (1000) #define TSDB_DATA_TYPE_VALUE_ARRAY (1001) +#define COPY_DATA(dst, src) *((int64_t *)(dst)) = *((int64_t *)(src)) + +#define COPY_TYPED_DATA(_v, _type, _data) \ + do { \ + switch (_type) { \ + case TSDB_DATA_TYPE_BOOL: \ + case TSDB_DATA_TYPE_TINYINT: \ + (*(int8_t *)_v) = GET_INT8_VAL(_data); \ + break; \ + case TSDB_DATA_TYPE_UTINYINT: \ + (*(uint8_t *)_v) = GET_UINT8_VAL(_data); \ + break; \ + case TSDB_DATA_TYPE_SMALLINT: \ + (*(int16_t *)_v) = GET_INT16_VAL(_data); \ + break; \ + case TSDB_DATA_TYPE_USMALLINT: \ + (*(uint16_t *)_v) = GET_UINT16_VAL(_data); \ + break; \ + case TSDB_DATA_TYPE_TIMESTAMP: \ + case TSDB_DATA_TYPE_BIGINT: \ + (*(int64_t *)_v) = (GET_INT64_VAL(_data)); \ + break; \ + case TSDB_DATA_TYPE_UBIGINT: \ + (*(uint64_t *)_v) = (GET_UINT64_VAL(_data)); \ + break; \ + case TSDB_DATA_TYPE_FLOAT: \ + (*(float *)_v) = GET_FLOAT_VAL(_data); \ + break; \ + case TSDB_DATA_TYPE_DOUBLE: \ + (*(double *)_v) = GET_DOUBLE_VAL(_data); \ + break; \ + case TSDB_DATA_TYPE_UINT: \ + (*(uint32_t *)_v) = GET_UINT32_VAL(_data); \ + break; \ + default: \ + (*(int32_t *)_v) = GET_INT32_VAL(_data); \ + break; \ + } \ + } while (0) + + #define GET_TYPED_DATA(_v, _finalType, _type, _data) \ do { \ switch (_type) { \ diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 1451a1843a..dcb7598063 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -3913,11 +3913,11 @@ static void interp_function(SQLFunctionCtx *pCtx) { if (pCtx->start.key == pCtx->startTs) { assert(pCtx->start.key != INT64_MIN); - SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, *(double *)&pCtx->start.val); + COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->start.val); goto interp_success_exit; } else if (pCtx->end.key == pCtx->startTs && pCtx->end.key != INT64_MIN && fillType == TSDB_FILL_NEXT) { - SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, *(double *)&pCtx->end.val); + COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->end.val); goto interp_success_exit; } @@ -3936,6 +3936,9 @@ static void interp_function(SQLFunctionCtx *pCtx) { || pCtx->end.key == INT64_MIN || pCtx->end.key < pCtx->startTs) { goto interp_exit; } + + GET_TYPED_DATA(pCtx->start.val, double, pCtx->inputType, &pCtx->start.val); + GET_TYPED_DATA(pCtx->end.val, double, pCtx->inputType, &pCtx->end.val); SPoint point1 = {.key = pCtx->start.key, .val = &pCtx->start.val}; SPoint point2 = {.key = pCtx->end.key, .val = &pCtx->end.val}; @@ -3954,7 +3957,7 @@ static void interp_function(SQLFunctionCtx *pCtx) { goto interp_exit; } - SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, *(double *)&pCtx->start.val); + COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->start.val); break; case TSDB_FILL_NEXT: @@ -3962,7 +3965,7 @@ static void interp_function(SQLFunctionCtx *pCtx) { goto interp_exit; } - SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, *(double *)&pCtx->end.val); + COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->end.val); break; case TSDB_FILL_NONE: diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 93680cd336..077d00e410 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1260,13 +1260,12 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo, if (functionId == TSDB_FUNC_INTERP) { if (type == RESULT_ROW_START_INTERP) { if (prevRowIndex == -1) { - GET_TYPED_DATA(v1, double, pColInfo->info.type, (char *)pRuntimeEnv->prevRow[index]); + COPY_DATA(&pCtx[k].start.val, (char *)pRuntimeEnv->prevRow[index]); } else { - GET_TYPED_DATA(v1, double, pColInfo->info.type, (char *)pColInfo->pData + prevRowIndex * pColInfo->info.bytes); + COPY_DATA(&pCtx[k].start.val, (char *)pColInfo->pData + prevRowIndex * pColInfo->info.bytes); } pCtx[k].start.key = prevTs; - pCtx[k].start.val = v1; if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { if (prevRowIndex == -1) { @@ -1278,13 +1277,12 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo, } else { if (curRowIndex == -1) { - GET_TYPED_DATA(v2, double, pColInfo->info.type, (char *)pRuntimeEnv->prevRow[index]); + COPY_DATA(&pCtx[k].end.val, pRuntimeEnv->prevRow[index]); } else { - GET_TYPED_DATA(v2, double, pColInfo->info.type, (char *)pColInfo->pData + curRowIndex * pColInfo->info.bytes); + COPY_DATA(&pCtx[k].end.val, (char *)pColInfo->pData + curRowIndex * pColInfo->info.bytes); } pCtx[k].end.key = curTs; - pCtx[k].end.val = v2; if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { pCtx[k].end.ptr = (char *)pColInfo->pData + curRowIndex * pColInfo->info.bytes; -- GitLab