From 074bb67be3199661664ded3667fd4d18311b2844 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 12 Nov 2021 11:47:53 +0800 Subject: [PATCH] [TD-10979]fix int64 overflow issue --- src/query/inc/qFill.h | 2 +- src/query/src/qAggMain.c | 10 +++++----- src/query/src/qExecutor.c | 4 ++-- src/query/src/qFill.c | 11 +++++++---- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/query/inc/qFill.h b/src/query/inc/qFill.h index abed3d8c01..2bf0ca8b55 100644 --- a/src/query/inc/qFill.h +++ b/src/query/inc/qFill.h @@ -86,7 +86,7 @@ bool taosFillHasMoreResults(SFillInfo* pFillInfo); int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, int64_t ekey, int32_t maxNumOfRows); -int32_t taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint* point1, SPoint* point2, int32_t inputType, bool *exceedMax); +int32_t taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint* point1, SPoint* point2, int32_t inputType, bool *exceedMax, bool *exceedMin); int64_t taosFillResultDataBlock(SFillInfo* pFillInfo, void** output, int32_t capacity); diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index a7c6d4571a..1be10ea88c 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -3950,14 +3950,14 @@ static void interp_function(SQLFunctionCtx *pCtx) { if (isNull((char *)&pCtx->start.val, srcType) || isNull((char *)&pCtx->end.val, srcType)) { setNull(pCtx->pOutput, srcType, pCtx->inputBytes); } else { - bool exceedMax = false; - taosGetLinearInterpolationVal(&point, pCtx->outputType, &point1, &point2, TSDB_DATA_TYPE_DOUBLE, &exceedMax); - if (exceedMax) { + bool exceedMax = false, exceedMin = false; + taosGetLinearInterpolationVal(&point, pCtx->outputType, &point1, &point2, TSDB_DATA_TYPE_DOUBLE, &exceedMax, &exceedMin); + if (exceedMax || exceedMin) { __compar_fn_t func = getComparFunc((int32_t)pCtx->inputType, 0); if (func(&pCtx->start.val, &pCtx->end.val) <= 0) { - COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->start.val); + COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, exceedMax ? &pCtx->start.val : &pCtx->end.val); } else { - COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->end.val); + COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, exceedMax ? &pCtx->end.val : &pCtx->start.val); } } } diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index a098e49359..05902cccd0 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1303,8 +1303,8 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo, SPoint point2 = (SPoint){.key = curTs, .val = &v2}; SPoint point = (SPoint){.key = windowKey, .val = &v }; - bool exceedMax = false; - taosGetLinearInterpolationVal(&point, TSDB_DATA_TYPE_DOUBLE, &point1, &point2, TSDB_DATA_TYPE_DOUBLE, &exceedMax); + bool exceedMax = false, exceedMin = false; + taosGetLinearInterpolationVal(&point, TSDB_DATA_TYPE_DOUBLE, &point1, &point2, TSDB_DATA_TYPE_DOUBLE, &exceedMax, &exceedMin); if (type == RESULT_ROW_START_INTERP) { pCtx[k].start.key = point.key; diff --git a/src/query/src/qFill.c b/src/query/src/qFill.c index 24acdc0b2e..b0015e39b9 100644 --- a/src/query/src/qFill.c +++ b/src/query/src/qFill.c @@ -118,11 +118,11 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, void** data, char** srcData continue; } - bool exceedMax = false; + bool exceedMax = false, exceedMin = false; point1 = (SPoint){.key = *(TSKEY*)(prev), .val = prev + pCol->col.offset}; point2 = (SPoint){.key = ts, .val = srcData[i] + pFillInfo->index * bytes}; point = (SPoint){.key = pFillInfo->currentKey, .val = val1}; - taosGetLinearInterpolationVal(&point, type, &point1, &point2, type, &exceedMax); + taosGetLinearInterpolationVal(&point, type, &point1, &point2, type, &exceedMax, &exceedMin); } } else { setNullValueForRow(pFillInfo, data, pFillInfo->numOfCols, index); @@ -494,15 +494,18 @@ int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, TSKEY ekey, int32_t ma return (numOfRes > maxNumOfRows) ? maxNumOfRows : numOfRes; } -int32_t taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint* point1, SPoint* point2, int32_t inputType, bool *exceedMax) { - double v1 = -1, v2 = -1, vmax = -1; +int32_t taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint* point1, SPoint* point2, int32_t inputType, bool *exceedMax, bool *exceedMin) { + double v1 = -1, v2 = -1, vmax = -1, vmin = -1; GET_TYPED_DATA(v1, double, inputType, point1->val); GET_TYPED_DATA(v2, double, inputType, point2->val); GET_TYPED_DATA(vmax, double, outputType, getDataMax(outputType)); + GET_TYPED_DATA(vmin, double, outputType, getDataMin(outputType)); double r = DO_INTERPOLATION(v1, v2, point1->key, point2->key, point->key); if (r >= vmax) { *exceedMax = true; + } else if (r <= vmin) { + *exceedMin = true; } SET_TYPED_DATA(point->val, outputType, r); -- GitLab