diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 99177913126b3da573fb9a006171f1dbae686d6b..8f76a3d72f387b993c7ce382543860578d4f051c 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -1273,6 +1273,14 @@ static void doCopyResultToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SR pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset); if (pCtx[j].fpSet.finalize) { + if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0) { + // for groupkey along with functions output multiple lines(e.g. Histogram) + // need to fill groupkey result for each output row. + if (pCtx[j].resultInfo->numOfRes != 0) { + pCtx[j].resultInfo->numOfRes = pRow->numOfRows; + } + } + int32_t code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock); if (TAOS_FAILED(code)) { qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(code)); diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index a8d51905ab68ea40c7f35b8aa09116030dca7038..42512d3a11de0b5480d23a96fa463dc3572a370a 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -6157,7 +6157,10 @@ int32_t groupKeyFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SGroupKeyInfo* pInfo = GET_ROWCELL_INTERBUF(pResInfo); if (pInfo->hasResult) { - colDataAppend(pCol, pBlock->info.rows, pInfo->data, pInfo->isNull ? true : false); + int32_t currentRow = pBlock->info.rows; + for (; currentRow < pBlock->info.rows + pResInfo->numOfRes; ++currentRow) { + colDataAppend(pCol, currentRow, pInfo->data, pInfo->isNull ? true : false); + } } else { pResInfo->numOfRes = 0; }