diff --git a/src/query/src/qFill.c b/src/query/src/qFill.c index 275ffb9ef8424ea0933e1925c5fbf4fe3656eda3..f160a8c91ea15bbd2265dd8c928cc097b3157586 100644 --- a/src/query/src/qFill.c +++ b/src/query/src/qFill.c @@ -430,8 +430,6 @@ void taosFillSetStartInfo(SFillInfo* pFillInfo, int32_t numOfRows, TSKEY endKey) pFillInfo->end = endKey; if (!FILL_IS_ASC_FILL(pFillInfo)) { pFillInfo->end = taosTimeTruncate(endKey, &pFillInfo->interval, pFillInfo->precision); - if (numOfRows > 0) - pFillInfo->currentKey = pFillInfo->end; } pFillInfo->index = 0; @@ -451,6 +449,27 @@ void taosFillSetInputDataBlock(SFillInfo* pFillInfo, const SSDataBlock* pInput) memcpy(pTag->tagVal, pColData->pData, pCol->col.bytes); // TODO not memcpy?? } } + + // check currentKey validate + if (!FILL_IS_ASC_FILL(pFillInfo)) { + int64_t* tsList = (int64_t*) pFillInfo->pData[0]; + int32_t numOfRows = taosNumOfRemainRows(pFillInfo); + int64_t numOfRes = -1; + if (numOfRows > 0) { + TSKEY lastKey = tsList[pFillInfo->numOfRows - 1]; + numOfRes = taosTimeCountInterval( + lastKey, + pFillInfo->currentKey, + pFillInfo->interval.sliding, + pFillInfo->interval.slidingUnit, + pFillInfo->precision); + numOfRes += 1; + if(numOfRes < numOfRows) { + // reset current Key + pFillInfo->currentKey = tsList[0]; + } + } + } } bool taosFillHasMoreResults(SFillInfo* pFillInfo) {