From 63a917581d8a10dcfdcbfd1c0dd2ed74e34d0c6e Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 20 Jun 2022 16:11:42 +0800 Subject: [PATCH] fix(query): select last(*) from super table returns 0 if all columns are NULL. TD-16561 --- source/libs/function/src/builtinsimpl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index c72d7b5106..7440df062f 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -2563,9 +2563,6 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) { } static void firstLastTransferInfo(SFirstLastRes* pInput, SFirstLastRes* pOutput, bool isFirst) { - if (!pInput->hasResult) { - return; - } pOutput->bytes = pInput->bytes; TSKEY* tsIn = (TSKEY*)(pInput->buf + pInput->bytes); TSKEY* tsOut = (TSKEY*)(pOutput->buf + pInput->bytes); @@ -2599,7 +2596,9 @@ static int32_t firstLastFunctionMergeImpl(SqlFunctionCtx* pCtx, bool isFirstQuer firstLastTransferInfo(pInputInfo, pInfo, isFirstQuery); - SET_VAL(GET_RES_INFO(pCtx), 1, 1); + int32_t numOfElems = pInputInfo->hasResult ? 1 : 0; + + SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1); return TSDB_CODE_SUCCESS; } @@ -2624,6 +2623,7 @@ int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { int32_t firstLastPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(pCtx); SFirstLastRes* pRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + int32_t resultBytes = getFirstLastInfoSize(pRes->bytes); char* res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char)); -- GitLab