From b50462783061cd60df5146b83d13e1de9e540eb7 Mon Sep 17 00:00:00 2001 From: slzhou Date: Fri, 29 Mar 2024 17:01:56 +0800 Subject: [PATCH] fix: new group block to reset func input iter hasPrev --- include/libs/function/function.h | 7 ++----- source/libs/executor/src/tsort.c | 5 +++-- source/libs/function/src/builtinsimpl.c | 7 ++++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/libs/function/function.h b/include/libs/function/function.h index 78bd1d807b..6c60e1c4a8 100644 --- a/include/libs/function/function.h +++ b/include/libs/function/function.h @@ -212,11 +212,8 @@ typedef struct SFuncInputRowIter { char* pPrevPk; SSDataBlock* pPrevRowBlock; // pre one row block - //TODO: - // int32_t prevStartOffset; // for diff, derivative. - // SPoint1 prevStartPoint; // for twa. - // int32_t startOffset; // for diff, derivative. - // SPoint1 startPoint; // for twa. + uint64_t groupId; + bool hasGroupId; bool finalRow; } SFuncInputRowIter; diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 271d3e05a5..44404c345e 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -1306,6 +1306,7 @@ static void appendToRowIndexDataBlock(SSortHandle* pHandle, SSDataBlock* pSource static void initRowIdSort(SSortHandle* pHandle) { SBlockOrderInfo* pkOrder = (pHandle->bSortPk) ? taosArrayGet(pHandle->aExtRowsOrders, 1) : NULL; SColumnInfoData* extPkCol = (pHandle->bSortPk) ? taosArrayGet(pHandle->pDataBlock->pDataBlock, pkOrder->slotId) : NULL; + SColumnInfoData pkCol = {0}; SSDataBlock* pSortInput = createDataBlock(); SColumnInfoData tsCol = createColumnInfoData(TSDB_DATA_TYPE_TIMESTAMP, 8, 1); @@ -1317,7 +1318,7 @@ static void initRowIdSort(SSortHandle* pHandle) { SColumnInfoData lengthCol = createColumnInfoData(TSDB_DATA_TYPE_INT, 4, 4); blockDataAppendColInfo(pSortInput, &lengthCol); if (pHandle->bSortPk) { - SColumnInfoData pkCol = createColumnInfoData(extPkCol->info.type, extPkCol->info.bytes, 5); + pkCol = createColumnInfoData(extPkCol->info.type, extPkCol->info.bytes, 5); blockDataAppendColInfo(pSortInput, &pkCol); } blockDataDestroy(pHandle->pDataBlock); @@ -1343,7 +1344,7 @@ static void initRowIdSort(SSortHandle* pHandle) { biPk.order = pkOrder->order; biPk.slotId = 4; biPk.nullFirst = (biPk.order == TSDB_ORDER_ASC); - biPk.compFn = getKeyComparFunc(extPkCol->info.type, biPk.order); + biPk.compFn = getKeyComparFunc(pkCol.info.type, biPk.order); taosArrayPush(aOrder, &biPk); } taosArrayDestroy(pHandle->pSortInfo); diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index c029a809eb..fafc313afc 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -434,7 +434,12 @@ int32_t funcInputUpdate(SqlFunctionCtx* pCtx) { pIter->pPkCol = pIter->pInput->pPrimaryKey; pIter->rowIndex = pIter->pInput->startRowIndex; pIter->inputEndIndex = pIter->rowIndex + pIter->pInput->numOfRows - 1; - pIter->pSrcBlock = pCtx->pSrcBlock; + pIter->pSrcBlock = pCtx->pSrcBlock; + if (!pIter->hasGroupId || pIter->groupId != pIter->pSrcBlock->info.id.groupId) { + pIter->hasGroupId = true; + pIter->groupId = pIter->pSrcBlock->info.id.groupId; + pIter->hasPrev = false; + } } else { pIter->finalRow = true; }