提交 074bb67b 编写于 作者: D dapan1121

[TD-10979]fix int64 overflow issue

上级 730e91d4
...@@ -86,7 +86,7 @@ bool taosFillHasMoreResults(SFillInfo* pFillInfo); ...@@ -86,7 +86,7 @@ bool taosFillHasMoreResults(SFillInfo* pFillInfo);
int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, int64_t ekey, int32_t maxNumOfRows); 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); int64_t taosFillResultDataBlock(SFillInfo* pFillInfo, void** output, int32_t capacity);
......
...@@ -3950,14 +3950,14 @@ static void interp_function(SQLFunctionCtx *pCtx) { ...@@ -3950,14 +3950,14 @@ static void interp_function(SQLFunctionCtx *pCtx) {
if (isNull((char *)&pCtx->start.val, srcType) || isNull((char *)&pCtx->end.val, srcType)) { if (isNull((char *)&pCtx->start.val, srcType) || isNull((char *)&pCtx->end.val, srcType)) {
setNull(pCtx->pOutput, srcType, pCtx->inputBytes); setNull(pCtx->pOutput, srcType, pCtx->inputBytes);
} else { } else {
bool exceedMax = false; bool exceedMax = false, exceedMin = false;
taosGetLinearInterpolationVal(&point, pCtx->outputType, &point1, &point2, TSDB_DATA_TYPE_DOUBLE, &exceedMax); taosGetLinearInterpolationVal(&point, pCtx->outputType, &point1, &point2, TSDB_DATA_TYPE_DOUBLE, &exceedMax, &exceedMin);
if (exceedMax) { if (exceedMax || exceedMin) {
__compar_fn_t func = getComparFunc((int32_t)pCtx->inputType, 0); __compar_fn_t func = getComparFunc((int32_t)pCtx->inputType, 0);
if (func(&pCtx->start.val, &pCtx->end.val) <= 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 { } 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);
} }
} }
} }
......
...@@ -1303,8 +1303,8 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo, ...@@ -1303,8 +1303,8 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo,
SPoint point2 = (SPoint){.key = curTs, .val = &v2}; SPoint point2 = (SPoint){.key = curTs, .val = &v2};
SPoint point = (SPoint){.key = windowKey, .val = &v }; SPoint point = (SPoint){.key = windowKey, .val = &v };
bool exceedMax = false; bool exceedMax = false, exceedMin = false;
taosGetLinearInterpolationVal(&point, TSDB_DATA_TYPE_DOUBLE, &point1, &point2, TSDB_DATA_TYPE_DOUBLE, &exceedMax); taosGetLinearInterpolationVal(&point, TSDB_DATA_TYPE_DOUBLE, &point1, &point2, TSDB_DATA_TYPE_DOUBLE, &exceedMax, &exceedMin);
if (type == RESULT_ROW_START_INTERP) { if (type == RESULT_ROW_START_INTERP) {
pCtx[k].start.key = point.key; pCtx[k].start.key = point.key;
......
...@@ -118,11 +118,11 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, void** data, char** srcData ...@@ -118,11 +118,11 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, void** data, char** srcData
continue; continue;
} }
bool exceedMax = false; bool exceedMax = false, exceedMin = false;
point1 = (SPoint){.key = *(TSKEY*)(prev), .val = prev + pCol->col.offset}; point1 = (SPoint){.key = *(TSKEY*)(prev), .val = prev + pCol->col.offset};
point2 = (SPoint){.key = ts, .val = srcData[i] + pFillInfo->index * bytes}; point2 = (SPoint){.key = ts, .val = srcData[i] + pFillInfo->index * bytes};
point = (SPoint){.key = pFillInfo->currentKey, .val = val1}; point = (SPoint){.key = pFillInfo->currentKey, .val = val1};
taosGetLinearInterpolationVal(&point, type, &point1, &point2, type, &exceedMax); taosGetLinearInterpolationVal(&point, type, &point1, &point2, type, &exceedMax, &exceedMin);
} }
} else { } else {
setNullValueForRow(pFillInfo, data, pFillInfo->numOfCols, index); setNullValueForRow(pFillInfo, data, pFillInfo->numOfCols, index);
...@@ -494,15 +494,18 @@ int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, TSKEY ekey, int32_t ma ...@@ -494,15 +494,18 @@ int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, TSKEY ekey, int32_t ma
return (numOfRes > maxNumOfRows) ? maxNumOfRows : numOfRes; return (numOfRes > maxNumOfRows) ? maxNumOfRows : numOfRes;
} }
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) {
double v1 = -1, v2 = -1, vmax = -1; double v1 = -1, v2 = -1, vmax = -1, vmin = -1;
GET_TYPED_DATA(v1, double, inputType, point1->val); GET_TYPED_DATA(v1, double, inputType, point1->val);
GET_TYPED_DATA(v2, double, inputType, point2->val); GET_TYPED_DATA(v2, double, inputType, point2->val);
GET_TYPED_DATA(vmax, double, outputType, getDataMax(outputType)); 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); double r = DO_INTERPOLATION(v1, v2, point1->key, point2->key, point->key);
if (r >= vmax) { if (r >= vmax) {
*exceedMax = true; *exceedMax = true;
} else if (r <= vmin) {
*exceedMin = true;
} }
SET_TYPED_DATA(point->val, outputType, r); SET_TYPED_DATA(point->val, outputType, r);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册