diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 95b4afe6d8d1b84735c08b2c5f907c85db5d92ef..07d8a2e6a7aac383aa89c346173546341125771b 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -3329,7 +3329,7 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTabl if (pCond->type == TIMEWINDOW_RANGE_EXTERNAL) { // update the SQueryTableDataCond to create inner reader - int32_t order = pCond->order; + int32_t order = pCond->order; if (order == TSDB_ORDER_ASC) { pCond->twindows.ekey = window.skey; pCond->twindows.skey = INT64_MIN; @@ -3353,6 +3353,8 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTabl pCond->twindows.skey = INT64_MIN; pCond->twindows.ekey = window.ekey; } + pCond->order = order; + code = tsdbReaderCreate(pVnode, pCond, &pReader->innerReader[1], 1, idstr); if (code != TSDB_CODE_SUCCESS) { goto _err; @@ -3373,8 +3375,10 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTabl } } + STsdbReader* p = pReader->innerReader[0] != NULL? pReader->innerReader[0]:pReader; + int32_t numOfTables = taosArrayGetSize(pTableList); - pReader->status.pTableMap = createDataBlockScanInfo(pReader, pTableList->pData, numOfTables); + pReader->status.pTableMap = createDataBlockScanInfo(p, pTableList->pData, numOfTables); if (pReader->status.pTableMap == NULL) { tsdbReaderClose(pReader); *ppReader = NULL; @@ -3541,8 +3545,9 @@ bool tsdbNextDataBlock(STsdbReader* pReader) { if (pReader->innerReader[0] != NULL && pReader->step == 0) { bool ret = doTsdbNextDataBlock(pReader->innerReader[0]); resetDataBlockScanInfo(pReader->innerReader[0]->status.pTableMap, pReader->innerReader[0]->window.ekey); + pReader->step = EXTERNAL_ROWS_PREV; + if (ret) { - pReader->step = EXTERNAL_ROWS_PREV; return ret; } } @@ -3559,8 +3564,8 @@ bool tsdbNextDataBlock(STsdbReader* pReader) { if (pReader->innerReader[1] != NULL && pReader->step == EXTERNAL_ROWS_MAIN) { resetDataBlockScanInfo(pReader->innerReader[1]->status.pTableMap, pReader->window.ekey); bool ret1 = doTsdbNextDataBlock(pReader->innerReader[1]); + pReader->step = EXTERNAL_ROWS_NEXT; if (ret1) { - pReader->step = EXTERNAL_ROWS_NEXT; return ret1; } } diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index 0c6cc51efdf2bdbf52ef5de52efc696a2930793c..8ddaca5b706a43b16b67144b0fda601b65434338 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -1994,7 +1994,7 @@ static void doKeepLinearInfo(STimeSliceOperatorInfo* pSliceInfo, const SSDataBlo } } - pSliceInfo->fillLastPoint = isLastRow ? true : false; + pSliceInfo->fillLastPoint = isLastRow; } static void genInterpolationResult(STimeSliceOperatorInfo* pSliceInfo, SExprSupp* pExprSup, SSDataBlock* pResBlock) { @@ -2342,6 +2342,9 @@ static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) { break; } } + } else { + // store ts value as start, and calculate interp value when processing next block + doKeepLinearInfo(pSliceInfo, pBlock, i, true); } } else { // non-linear interpolation if (i < pBlock->info.rows - 1) { @@ -2420,6 +2423,9 @@ static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) { break; } } + } else { // it is the last row of current block + // store ts value as start, and calculate interp value when processing next block + doKeepLinearInfo(pSliceInfo, pBlock, i, true); } } else { // non-linear interpolation pSliceInfo->current =