From 16a4b6aa35f5cd0da41949d65b03e812cbdf2785 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sat, 2 Jul 2022 03:38:18 +0200 Subject: [PATCH 1/3] Fix a bug in `rankCorr` function --- tests/queries/0_stateless/02347_rank_corr_nan.reference | 1 + tests/queries/0_stateless/02347_rank_corr_nan.sql | 1 + 2 files changed, 2 insertions(+) create mode 100644 tests/queries/0_stateless/02347_rank_corr_nan.reference create mode 100644 tests/queries/0_stateless/02347_rank_corr_nan.sql diff --git a/tests/queries/0_stateless/02347_rank_corr_nan.reference b/tests/queries/0_stateless/02347_rank_corr_nan.reference new file mode 100644 index 00000000000..6db331af725 --- /dev/null +++ b/tests/queries/0_stateless/02347_rank_corr_nan.reference @@ -0,0 +1 @@ +nan diff --git a/tests/queries/0_stateless/02347_rank_corr_nan.sql b/tests/queries/0_stateless/02347_rank_corr_nan.sql new file mode 100644 index 00000000000..0fd755259e6 --- /dev/null +++ b/tests/queries/0_stateless/02347_rank_corr_nan.sql @@ -0,0 +1 @@ +SELECT rankCorr(number, nan) FROM numbers(10); From 668f06b2dbefee3956a24723996422277e82b1e5 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sat, 2 Jul 2022 03:40:20 +0200 Subject: [PATCH 2/3] Fix error --- .../AggregateFunctionRankCorrelation.h | 4 ++-- src/AggregateFunctions/StatCommon.h | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/AggregateFunctions/AggregateFunctionRankCorrelation.h b/src/AggregateFunctions/AggregateFunctionRankCorrelation.h index a9bf8254f35..670dd5948f7 100644 --- a/src/AggregateFunctions/AggregateFunctionRankCorrelation.h +++ b/src/AggregateFunctions/AggregateFunctionRankCorrelation.h @@ -31,8 +31,8 @@ struct RankCorrelationData : public StatisticalSample RanksArray ranks_y; std::tie(ranks_y, std::ignore) = computeRanksAndTieCorrection(this->y); - /// In our case sizes of both samples are equal. - const auto size = this->size_x; + /// Sizes can be non-equal due to skipped NaNs. + const auto size = std::min(this->size_x, this->size_y); /// Count d^2 sum Float64 answer = 0; diff --git a/src/AggregateFunctions/StatCommon.h b/src/AggregateFunctions/StatCommon.h index 29163b63f77..ff824ca11b8 100644 --- a/src/AggregateFunctions/StatCommon.h +++ b/src/AggregateFunctions/StatCommon.h @@ -31,8 +31,8 @@ std::pair computeRanksAndTieCorrection(const Values & value /// Save initial positions, than sort indices according to the values. std::vector indexes(size); std::iota(indexes.begin(), indexes.end(), 0); - ::sort(indexes.begin(), indexes.end(), - [&] (size_t lhs, size_t rhs) { return values[lhs] < values[rhs]; }); + std::sort(indexes.begin(), indexes.end(), + [&] (size_t lhs, size_t rhs) { return values[lhs] < values[rhs]; }); size_t left = 0; Float64 tie_numenator = 0; @@ -74,12 +74,18 @@ struct StatisticalSample void addX(X value, Arena * arena) { + if (isNaN(value)) + return; + ++size_x; x.push_back(value, arena); } void addY(Y value, Arena * arena) { + if (isNaN(value)) + return; + ++size_y; y.push_back(value, arena); } From 4ba4329e0de3e853ca3da7892d4aeedc7ff848df Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sat, 2 Jul 2022 19:48:42 +0200 Subject: [PATCH 3/3] Fix bad test --- .../queries/0_stateless/01848_http_insert_segfault.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/queries/0_stateless/01848_http_insert_segfault.sh b/tests/queries/0_stateless/01848_http_insert_segfault.sh index c766e9794ae..1f2e9eebcdc 100755 --- a/tests/queries/0_stateless/01848_http_insert_segfault.sh +++ b/tests/queries/0_stateless/01848_http_insert_segfault.sh @@ -1,7 +1,9 @@ #!/usr/bin/env bash +# Tags: no-tsan +# Sometimes is takes longer than 60 seconds under TSan. - CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) - # shellcheck source=../shell_config.sh - . "$CUR_DIR"/../shell_config.sh +CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CUR_DIR"/../shell_config.sh - ${CLICKHOUSE_LOCAL} -q "select col1, initializeAggregation('argMaxState', col2, insertTime) as col2, now() as insertTime FROM generateRandom('col1 String, col2 Array(Float64)') LIMIT 1000000 FORMAT CSV" | ${CLICKHOUSE_CURL} -s 'http://localhost:8123/?query=INSERT%20INTO%20non_existing_table%20SELECT%20col1%2C%20initializeAggregation(%27argMaxState%27%2C%20col2%2C%20insertTime)%20as%20col2%2C%20now()%20as%20insertTime%20FROM%20input(%27col1%20String%2C%20col2%20Array(Float64)%27)%20FORMAT%20CSV' --data-binary @- | grep -q "Table default.non_existing_table doesn't exist" && echo 'Ok.' || echo 'FAIL' ||: +${CLICKHOUSE_LOCAL} --query "select col1, initializeAggregation('argMaxState', col2, insertTime) as col2, now() as insertTime FROM generateRandom('col1 String, col2 Array(Float64)') LIMIT 1000000 FORMAT CSV" | ${CLICKHOUSE_CURL} -s 'http://localhost:8123/?query=INSERT%20INTO%20non_existing_table%20SELECT%20col1%2C%20initializeAggregation(%27argMaxState%27%2C%20col2%2C%20insertTime)%20as%20col2%2C%20now()%20as%20insertTime%20FROM%20input(%27col1%20String%2C%20col2%20Array(Float64)%27)%20FORMAT%20CSV' --data-binary @- | grep -q "Table default.non_existing_table doesn't exist" && echo 'Ok.' || echo 'FAIL' ||: