From 34f598e09b7ac23c8fae234a3a132a5a85c45efa Mon Sep 17 00:00:00 2001 From: Duc Canh Le Date: Mon, 3 Oct 2022 19:55:37 +0800 Subject: [PATCH] fix rankcorr size overflow --- src/AggregateFunctions/AggregateFunctionRankCorrelation.h | 2 +- .../queries/0_stateless/02347_rank_corr_size_overflow.reference | 1 + tests/queries/0_stateless/02347_rank_corr_size_overflow.sql | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/02347_rank_corr_size_overflow.reference create mode 100644 tests/queries/0_stateless/02347_rank_corr_size_overflow.sql diff --git a/src/AggregateFunctions/AggregateFunctionRankCorrelation.h b/src/AggregateFunctions/AggregateFunctionRankCorrelation.h index 670dd5948f7..e05b6dc1608 100644 --- a/src/AggregateFunctions/AggregateFunctionRankCorrelation.h +++ b/src/AggregateFunctions/AggregateFunctionRankCorrelation.h @@ -32,7 +32,7 @@ struct RankCorrelationData : public StatisticalSample std::tie(ranks_y, std::ignore) = computeRanksAndTieCorrection(this->y); /// Sizes can be non-equal due to skipped NaNs. - const auto size = std::min(this->size_x, this->size_y); + const Float32 size = static_cast(std::min(this->size_x, this->size_y)); /// Count d^2 sum Float64 answer = 0; diff --git a/tests/queries/0_stateless/02347_rank_corr_size_overflow.reference b/tests/queries/0_stateless/02347_rank_corr_size_overflow.reference new file mode 100644 index 00000000000..3a2e3f4984a --- /dev/null +++ b/tests/queries/0_stateless/02347_rank_corr_size_overflow.reference @@ -0,0 +1 @@ +-1 diff --git a/tests/queries/0_stateless/02347_rank_corr_size_overflow.sql b/tests/queries/0_stateless/02347_rank_corr_size_overflow.sql new file mode 100644 index 00000000000..3ca1ced8dd5 --- /dev/null +++ b/tests/queries/0_stateless/02347_rank_corr_size_overflow.sql @@ -0,0 +1 @@ +SELECT round(rankCorr(number, -number)) FROM numbers(5000000);