Skip to content

Commit

Permalink
Merge pull request #27693 from taosdata/fix/main/TD-31889
Browse files Browse the repository at this point in the history
fix:[TD-31889] extend result buf size for percentile function to handle large double value.
  • Loading branch information
dapan1121 authored Sep 6, 2024
2 parents 3309f88 + 7fa2368 commit e5e1f90
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/libs/function/src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
Expand Down
3 changes: 2 additions & 1 deletion source/libs/function/src/builtinsimpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] = '[';
Expand Down
6 changes: 6 additions & 0 deletions tests/system-test/2-query/percentile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit e5e1f90

Please sign in to comment.