diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index cc013b7dca7a..7a35e0972005 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -616,7 +616,7 @@ static int32_t translatePercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t // set result type if (numOfParams > 2) { - pFunc->node.resType = (SDataType){.bytes = 512, .type = TSDB_DATA_TYPE_VARCHAR}; + pFunc->node.resType = (SDataType){.bytes = 3200, .type = TSDB_DATA_TYPE_VARCHAR}; } else { pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE}; } diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 1bb28765ba96..5e801e922ffd 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -1984,7 +1984,8 @@ int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { tMemBucket* pMemBucket = ppInfo->pMemBucket; if (pMemBucket != NULL && pMemBucket->total > 0) { // check for null if (pCtx->numOfParams > 2) { - char buf[512] = {0}; + char buf[3200] = {0}; + // max length of double num is 317, e.g. use %.6lf to print -1.0e+308, consider the comma and bracket, 3200 is enough. size_t len = 1; varDataVal(buf)[0] = '['; diff --git a/tests/system-test/2-query/percentile.py b/tests/system-test/2-query/percentile.py index e01aae97c00e..46fff0201eef 100644 --- a/tests/system-test/2-query/percentile.py +++ b/tests/system-test/2-query/percentile.py @@ -124,6 +124,9 @@ def function_check_ntb(self): tdSql.query(f'select percentile(col1, 9.9, 19.9, 29.9, 39.9, 49.9, 59.9, 69.9, 79.9, 89.9, 99.9) from {self.ntbname}') tdSql.checkData(0, 0, '[0.891000, 1.791000, 2.691000, 3.591000, 4.491000, 5.391000, 6.291000, 7.191000, 8.091000, 8.991000]') + tdSql.query(f'select percentile(col1 * 1e+200, 9.9, 19.9, 29.9, 39.9, 49.9, 59.9, 69.9, 79.9, 89.9, 99.9) from {self.ntbname}') + tdSql.checkRows(1); + tdSql.error(f'select percentile(col1) from {self.ntbname}') tdSql.error(f'select percentile(col1, -1) from {self.ntbname}') tdSql.error(f'select percentile(col1, 101) from {self.ntbname}') @@ -166,6 +169,9 @@ def function_check_ctb(self): tdSql.query(f'select percentile(col1, 9.9, 19.9, 29.9, 39.9, 49.9, 59.9, 69.9, 79.9, 89.9, 99.9) from {self.stbname}_0') tdSql.checkData(0, 0, '[0.891000, 1.791000, 2.691000, 3.591000, 4.491000, 5.391000, 6.291000, 7.191000, 8.091000, 8.991000]') + tdSql.query(f'select percentile(col1 * 1e+200, 9.9, 19.9, 29.9, 39.9, 49.9, 59.9, 69.9, 79.9, 89.9, 99.9) from {self.stbname}_0') + tdSql.checkRows(1); + tdSql.error(f'select percentile(col1) from {self.stbname}_0') tdSql.error(f'select percentile(col1, -1) from {self.stbname}_0') tdSql.error(f'select percentile(col1, 101) from {self.stbname}_0')