From fbd648b5f2a4b91527f1ee351b1817dc6a329fe1 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 16 Aug 2021 17:57:08 +0800 Subject: [PATCH] [TD-6046] fix ts,derivative() output error for top/bottom/diff/derivative --- src/query/src/qExecutor.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 4ce9a1d849..caa6620b73 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -3616,19 +3616,32 @@ void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOf } char *tsbuf = NULL; + int16_t tsFuncIndex = -1; + for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) { + SColumnInfoData* pColInfo = taosArrayGet(pDataBlock->pDataBlock, i); + + // find the ts output data pointer + int32_t functionId = pBInfo->pCtx[i].functionId; + if (functionId == TSDB_FUNC_PRJ && pColInfo->info.type == TSDB_DATA_TYPE_TIMESTAMP) { + tsbuf = pColInfo->pData + pColInfo->info.bytes * pDataBlock->info.rows; + tsFuncIndex = i; + break; + } + } + for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) { SColumnInfoData *pColInfo = taosArrayGet(pDataBlock->pDataBlock, i); pBInfo->pCtx[i].pOutput = pColInfo->pData + pColInfo->info.bytes * pDataBlock->info.rows; // re-estabilish output buffer pointer. int32_t functionId = pBInfo->pCtx[i].functionId; - if (functionId == TSDB_FUNC_PRJ && pColInfo->info.type == TSDB_DATA_TYPE_TIMESTAMP){ - tsbuf = pBInfo->pCtx[i].pOutput; - } - else if ((i > 0) && + if ((i > 0) && (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE)) { pBInfo->pCtx[i].ptsOutputBuf = pBInfo->pCtx[i-1].pOutput; pBInfo->pCtx[i].ptsOriOutputBuf = tsbuf; + if(tsFuncIndex != -1) { + pBInfo->pCtx[tsFuncIndex].functionId = TSDB_FUNC_TS_DUMMY; // to avoid query data + } } } } -- GitLab