This is an automated email from the ASF dual-hosted git repository. dataroaring pushed a commit to branch branch-3.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push: new f5f3c6c12c2 [Bug](agg) percentile_approx_weighted function should sure the input value is valid (#39929) f5f3c6c12c2 is described below commit f5f3c6c12c2cbbd0aa7aab07685df32654f35d9f Author: zhangstar333 <87313068+zhangstar...@users.noreply.github.com> 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 2deaaf848df..5217ba5aeb5 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: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org