This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 36ab3e06b7f [Bug](agg) percentile_approx_weighted function should sure
the input value is valid (#39929)
36ab3e06b7f is described below
commit 36ab3e06b7f2c247f0130454f9085d5041b64981
Author: zhangstar333 <[email protected]>
AuthorDate: Tue Aug 27 15:00:36 2024 +0800
[Bug](agg) percentile_approx_weighted function should sure the input value
is valid (#39929)
## Proposed changes
the weight should be positive num, as have check the value valid use
DCHECK_GT(c._weight, 0) in Centroid;
```
void add(const Centroid& c) {
DCHECK_GT(c._weight, 0);
if (_weight != 0.0) {
_weight += c._weight;
_mean += c._weight * (c._mean - _mean) / _weight;
} else {
_weight = c._weight;
_mean = c._mean;
}
}
```
<!--Describe your changes.-->
---
.../vec/aggregate_functions/aggregate_function_percentile.h | 4 ++++
.../test_aggregate_percentile_approx_weighted.out | 3 +++
.../test_aggregate_percentile_approx_weighted.groovy | 11 ++++++++++-
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/be/src/vec/aggregate_functions/aggregate_function_percentile.h
b/be/src/vec/aggregate_functions/aggregate_function_percentile.h
index fe3e1886187..aae66eb4f78 100644
--- a/be/src/vec/aggregate_functions/aggregate_function_percentile.h
+++ b/be/src/vec/aggregate_functions/aggregate_function_percentile.h
@@ -132,6 +132,10 @@ struct PercentileApproxState {
}
void add_with_weight(double source, double weight, double quantile) {
+ // the weight should be positive num, as have check the value valid
use DCHECK_GT(c._weight, 0);
+ if (weight <= 0) {
+ return;
+ }
digest->add(source, weight);
target_quantile = quantile;
}
diff --git
a/regression-test/data/nereids_p0/sql_functions/aggregate_functions/test_aggregate_percentile_approx_weighted.out
b/regression-test/data/nereids_p0/sql_functions/aggregate_functions/test_aggregate_percentile_approx_weighted.out
index 0f86d83c18f..bf30d553341 100644
---
a/regression-test/data/nereids_p0/sql_functions/aggregate_functions/test_aggregate_percentile_approx_weighted.out
+++
b/regression-test/data/nereids_p0/sql_functions/aggregate_functions/test_aggregate_percentile_approx_weighted.out
@@ -5,3 +5,6 @@
-- !select --
1.0 1.6437499523162842 2.5900001525878906 4.539999485015869
6.0
+-- !select_3 --
+1.0 1.6437499523162842 2.5900001525878906 4.539999485015869
6.0
+
diff --git
a/regression-test/suites/nereids_p0/sql_functions/aggregate_functions/test_aggregate_percentile_approx_weighted.groovy
b/regression-test/suites/nereids_p0/sql_functions/aggregate_functions/test_aggregate_percentile_approx_weighted.groovy
index 99d8d688599..ed30b525a49 100644
---
a/regression-test/suites/nereids_p0/sql_functions/aggregate_functions/test_aggregate_percentile_approx_weighted.groovy
+++
b/regression-test/suites/nereids_p0/sql_functions/aggregate_functions/test_aggregate_percentile_approx_weighted.groovy
@@ -58,5 +58,14 @@ suite("test_aggregate_percentile_approx_weighted") {
percentile_approx_weighted(k,w,0.99,2048)
from quantile_weighted_table;
"""
-
+ sql """insert into quantile_weighted_table values(7,0),(8,-1);"""
+ qt_select_3 """
+ select
+ percentile_approx_weighted(k,w,0.1,2048),
+ percentile_approx_weighted(k,w,0.35,2048),
+ percentile_approx_weighted(k,w,0.55,2048),
+ percentile_approx_weighted(k,w,0.78,2048),
+ percentile_approx_weighted(k,w,0.99,2048)
+ from quantile_weighted_table;
+ """
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]