Merge pull request #15443 from taosdata/enh/TD-17659

fix(query): fix sum/max/min null input
This commit is contained in:
Ganlin Zhao 2022-07-27 17:13:09 +08:00 committed by GitHub
commit c74c52d10c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 11 deletions

View File

@ -466,7 +466,7 @@ int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
pResInfo->isNullRes = (pResInfo->numOfRes == 0) ? 1 : 0; pResInfo->isNullRes = (pResInfo->isNullRes == 1) ? 1 : (pResInfo->numOfRes == 0);
char* in = GET_ROWCELL_INTERBUF(pResInfo); char* in = GET_ROWCELL_INTERBUF(pResInfo);
colDataAppend(pCol, pBlock->info.rows, in, pResInfo->isNullRes); colDataAppend(pCol, pBlock->info.rows, in, pResInfo->isNullRes);
@ -663,7 +663,8 @@ int32_t sumFunction(SqlFunctionCtx* pCtx) {
// check for overflow // check for overflow
if (IS_FLOAT_TYPE(type) && (isinf(pSumRes->dsum) || isnan(pSumRes->dsum))) { if (IS_FLOAT_TYPE(type) && (isinf(pSumRes->dsum) || isnan(pSumRes->dsum))) {
numOfElem = 0; GET_RES_INFO(pCtx)->isNullRes = 1;
numOfElem = 1;
} }
_sum_over: _sum_over:
@ -1605,7 +1606,7 @@ int32_t minmaxFunctionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
int32_t currentRow = pBlock->info.rows; int32_t currentRow = pBlock->info.rows;
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
pEntryInfo->isNullRes = (pEntryInfo->numOfRes == 0); pEntryInfo->isNullRes = (pEntryInfo->isNullRes == 1) ? 1 : (pEntryInfo->numOfRes == 0);
if (pCol->info.type == TSDB_DATA_TYPE_FLOAT) { if (pCol->info.type == TSDB_DATA_TYPE_FLOAT) {
float v = *(double*)&pRes->v; float v = *(double*)&pRes->v;

View File

@ -83,22 +83,22 @@ if $data11 != 3 then
goto loop0 goto loop0
endi endi
if $data12 != 10 then if $data12 != NULL then
print ======data12=$data12 print ======data12=$data12
goto loop0 goto loop0
endi endi
if $data13 != 10 then if $data13 != NULL then
print ======data13=$data13 print ======data13=$data13
goto loop0 goto loop0
endi endi
if $data14 != 1.100000000 then if $data14 != NULL then
print ======data14=$data14 print ======data14=$data14
return -1 return -1
endi endi
if $data15 != 0.000000000 then if $data15 != NULL then
print ======data15=$data15 print ======data15=$data15
return -1 return -1
endi endi
@ -141,22 +141,22 @@ if $data01 != 7 then
goto loop1 goto loop1
endi endi
if $data02 != 18 then if $data02 != NULL then
print =====data02=$data02 print =====data02=$data02
goto loop1 goto loop1
endi endi
if $data03 != 4 then if $data03 != NULL then
print =====data03=$data03 print =====data03=$data03
goto loop1 goto loop1
endi endi
if $data04 != 1.000000000 then if $data04 != NULL then
print ======$data04 print ======$data04
return -1 return -1
endi endi
if $data05 != 1.154700538 then if $data05 != NULL then
print ======$data05 print ======$data05
return -1 return -1
endi endi