From 43918a27f9f397f5c12387468f667845bf3ad6bd Mon Sep 17 00:00:00 2001 From: 54liuyao <54liuyao@163.com> Date: Wed, 2 Nov 2022 16:37:07 +0800 Subject: [PATCH] fix(function):if data is null, apercentile function should return null --- source/common/src/tdatablock.c | 16 ++++++ source/libs/function/src/builtinsimpl.c | 4 +- tests/script/tsim/parser/function.sim | 66 ++++++++++++++++++++++++- 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index b8436237c0..7997a1250d 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -1913,6 +1913,22 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf) len += snprintf(dumpBuf + len, size - len, " %25s |", pBuf); if (len >= size - 1) return dumpBuf; break; + case TSDB_DATA_TYPE_TINYINT: + len += snprintf(dumpBuf + len, size - len, " %15d |", *(int8_t*)var); + if (len >= size - 1) return dumpBuf; + break; + case TSDB_DATA_TYPE_UTINYINT: + len += snprintf(dumpBuf + len, size - len, " %15d |", *(uint8_t*)var); + if (len >= size - 1) return dumpBuf; + break; + case TSDB_DATA_TYPE_SMALLINT: + len += snprintf(dumpBuf + len, size - len, " %15d |", *(int16_t*)var); + if (len >= size - 1) return dumpBuf; + break; + case TSDB_DATA_TYPE_USMALLINT: + len += snprintf(dumpBuf + len, size - len, " %15d |", *(uint16_t*)var); + if (len >= size - 1) return dumpBuf; + break; case TSDB_DATA_TYPE_INT: len += snprintf(dumpBuf + len, size - len, " %15d |", *(int32_t*)var); if (len >= size - 1) return dumpBuf; diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 3c24f1f542..c8f0b3d826 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -2713,7 +2713,9 @@ int32_t apercentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { taosMemoryFree(res); } else { // no need to free // setNull(pCtx->pOutput, pCtx->outputType, pCtx->outputBytes); - return TSDB_CODE_SUCCESS; + // return TSDB_CODE_SUCCESS; + qDebug("%s get the final res, elements:%" PRId64 ", numOfEntry:%d. result is null", __FUNCTION__, + pInfo->pHisto->numOfElems, pInfo->pHisto->numOfEntries); } } diff --git a/tests/script/tsim/parser/function.sim b/tests/script/tsim/parser/function.sim index e3ef94e1cc..ec9cdf2666 100644 --- a/tests/script/tsim/parser/function.sim +++ b/tests/script/tsim/parser/function.sim @@ -1013,4 +1013,68 @@ sql_error select sum(cast(_wend as bigint)), a from ft1 state_window(a); sql_error create stream streams1 trigger at_once into streamt as select _wstart, sum(_wduration) from ft1 interval(10s); -sql_error create stream streams1 trigger at_once into streamt as select _wstart, sum(cast(_wend as bigint)) from ft1 interval(10s); \ No newline at end of file +sql_error create stream streams1 trigger at_once into streamt as select _wstart, sum(cast(_wend as bigint)) from ft1 interval(10s); + +sql create database test vgroups 1; +sql use test; +sql create table t1(ts timestamp, a int, b int , c int, d double); +sql insert into t1 values(1648791213000,1,1,3,1.0); +sql insert into t1 values(1648791223000,1,2,NULL,NULL); + +sleep 200 + +sql select apercentile(c, 50), apercentile(d, 50, "t-digest") from t1; + +if $data00 != 3.000000000 then + print ======data00=$data00 + return -1 +endi + +if $data01 != 1.000000000 then + print ======data01=$data01 + return -1 +endi + +sql select apercentile(c, 50) a, apercentile(d, 50, "t-digest") from t1 partition by b session(ts, 5s) order by a desc; + +if $data00 != 3.000000000 then + print ======data00=$data00 + return -1 +endi + +if $data01 != 1.000000000 then + print ======data01=$data01 + return -1 +endi + +if $data10 != NULL then + print ======data10=$data10 + return -1 +endi + +if $data11 != NULL then + print ======data11=$data11 + return -1 +endi + +sql select apercentile(c, 50) a, apercentile(d, 50, "t-digest") from t1 state_window(b) order by a desc; + +if $data00 != 3.000000000 then + print ======data00=$data00 + return -1 +endi + +if $data01 != 1.000000000 then + print ======data01=$data01 + return -1 +endi + +if $data10 != NULL then + print ======data10=$data10 + return -1 +endi + +if $data11 != NULL then + print ======data11=$data11 + return -1 +endi \ No newline at end of file -- GitLab