From 1ae71a858be9846256981ff198c1950356eb02de Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 23 Dec 2022 16:01:13 +0800 Subject: [PATCH] fix: fix none fill column value issue --- source/libs/executor/src/filloperator.c | 1 + source/libs/executor/src/tfill.c | 51 ++++++++++--------------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/source/libs/executor/src/filloperator.c b/source/libs/executor/src/filloperator.c index 8d5af64777..c52495e405 100644 --- a/source/libs/executor/src/filloperator.c +++ b/source/libs/executor/src/filloperator.c @@ -170,6 +170,7 @@ static SSDataBlock* doFillImpl(SOperatorInfo* pOperator) { // Fill the previous group data block, before handle the data block of new group. // Close the fill operation for previous group data block taosFillSetStartInfo(pInfo->pFillInfo, 0, pInfo->win.ekey); + pInfo->pFillInfo->prev.key = 0; } } diff --git a/source/libs/executor/src/tfill.c b/source/libs/executor/src/tfill.c index 9735ce40c9..ab1feabf60 100644 --- a/source/libs/executor/src/tfill.c +++ b/source/libs/executor/src/tfill.c @@ -37,6 +37,22 @@ static void doSetVal(SColumnInfoData* pDstColInfoData, int32_t rowIndex, const SGroupKeys* pKey); +static void setNotFillColumn(SFillInfo* pFillInfo, SColumnInfoData* pDstColInfo, int32_t rowIndex, int32_t colIdx) { + SRowVal* p = NULL; + if (FILL_IS_ASC_FILL(pFillInfo)) { + if (pFillInfo->prev.key != 0) { + p = &pFillInfo->prev; // prev has been set value + } else { // otherwise, use the value in the next row + p = &pFillInfo->next; + } + } else { + p = &pFillInfo->next; + } + + SGroupKeys* pKey = taosArrayGet(p->pRowVal, colIdx); + doSetVal(pDstColInfo, rowIndex, pKey); +} + static void setNullRow(SSDataBlock* pBlock, SFillInfo* pFillInfo, int32_t rowIndex) { for (int32_t i = 0; i < pFillInfo->numOfCols; ++i) { SFillColInfo* pCol = &pFillInfo->pFillCol[i]; @@ -45,19 +61,7 @@ static void setNullRow(SSDataBlock* pBlock, SFillInfo* pFillInfo, int32_t rowInd if (pCol->notFillCol) { bool filled = fillIfWindowPseudoColumn(pFillInfo, pCol, pDstColInfo, rowIndex); if (!filled) { - SRowVal* p = NULL; - if (FILL_IS_ASC_FILL(pFillInfo)) { - if (pFillInfo->prev.key != 0) { - p = &pFillInfo->prev; // prev has been set value - } else { // otherwise, use the value in the next row - p = &pFillInfo->next; - } - } else { - p = &pFillInfo->next; - } - - SGroupKeys* pKey = taosArrayGet(p->pRowVal, i); - doSetVal(pDstColInfo, rowIndex, pKey); + setNotFillColumn(pFillInfo, pDstColInfo, rowIndex, i); } } else { colDataAppendNULL(pDstColInfo, rowIndex); @@ -124,28 +128,23 @@ static void doFillOneRow(SFillInfo* pFillInfo, SSDataBlock* pBlock, SSDataBlock* // set the other values if (pFillInfo->type == TSDB_FILL_PREV) { - SArray* p = FILL_IS_ASC_FILL(pFillInfo) ? pFillInfo->prev.pRowVal : pFillInfo->next.pRowVal; - for (int32_t i = 0; i < pFillInfo->numOfCols; ++i) { SFillColInfo* pCol = &pFillInfo->pFillCol[i]; SColumnInfoData* pDstColInfoData = taosArrayGet(pBlock->pDataBlock, GET_DEST_SLOT_ID(pCol)); bool filled = fillIfWindowPseudoColumn(pFillInfo, pCol, pDstColInfoData, index); if (!filled) { - SGroupKeys* pKey = taosArrayGet(p, i); - doSetVal(pDstColInfoData, index, pKey); + setNotFillColumn(pFillInfo, pDstColInfoData, index, i); } } } else if (pFillInfo->type == TSDB_FILL_NEXT) { - SArray* p = FILL_IS_ASC_FILL(pFillInfo) ? pFillInfo->next.pRowVal : pFillInfo->prev.pRowVal; // todo refactor: start from 0 not 1 for (int32_t i = 0; i < pFillInfo->numOfCols; ++i) { SFillColInfo* pCol = &pFillInfo->pFillCol[i]; SColumnInfoData* pDstColInfoData = taosArrayGet(pBlock->pDataBlock, GET_DEST_SLOT_ID(pCol)); bool filled = fillIfWindowPseudoColumn(pFillInfo, pCol, pDstColInfoData, index); if (!filled) { - SGroupKeys* pKey = taosArrayGet(p, i); - doSetVal(pDstColInfoData, index, pKey); + setNotFillColumn(pFillInfo, pDstColInfoData, index, i); } } } else if (pFillInfo->type == TSDB_FILL_LINEAR) { @@ -163,9 +162,7 @@ static void doFillOneRow(SFillInfo* pFillInfo, SSDataBlock* pBlock, SSDataBlock* if (pCol->notFillCol) { bool filled = fillIfWindowPseudoColumn(pFillInfo, pCol, pDstCol, index); if (!filled) { - SArray* p = FILL_IS_ASC_FILL(pFillInfo) ? pFillInfo->prev.pRowVal : pFillInfo->next.pRowVal; - SGroupKeys* pKey = taosArrayGet(p, i); - doSetVal(pDstCol, index, pKey); + setNotFillColumn(pFillInfo, pDstCol, index, i); } } else { SGroupKeys* pKey = taosArrayGet(pFillInfo->prev.pRowVal, i); @@ -205,9 +202,7 @@ static void doFillOneRow(SFillInfo* pFillInfo, SSDataBlock* pBlock, SSDataBlock* if (pCol->notFillCol) { bool filled = fillIfWindowPseudoColumn(pFillInfo, pCol, pDst, index); if (!filled) { - SArray* p = FILL_IS_ASC_FILL(pFillInfo) ? pFillInfo->prev.pRowVal : pFillInfo->next.pRowVal; - SGroupKeys* pKey = taosArrayGet(p, i); - doSetVal(pDst, index, pKey); + setNotFillColumn(pFillInfo, pDst, index, i); } } else { SVariant* pVar = &pFillInfo->pFillCol[i].fillVal; @@ -297,10 +292,6 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, SSDataBlock* pBlock, int32_t copyCurrentRowIntoBuf(pFillInfo, pFillInfo->index, &pFillInfo->next); } - if (pFillInfo->currentKey < ts && ascFill && 0 == pFillInfo->index) { - copyCurrentRowIntoBuf(pFillInfo, pFillInfo->index, &pFillInfo->prev); - } - if (((pFillInfo->currentKey < ts && ascFill) || (pFillInfo->currentKey > ts && !ascFill)) && pFillInfo->numOfCurrent < outputRows) { // fill the gap between two input rows -- GitLab