From 893efab7c380b3b1abcee5277d99704a8a4039f3 Mon Sep 17 00:00:00 2001 From: sundy-li <543950155@qq.com> Date: Mon, 11 Jan 2021 10:05:37 +0800 Subject: [PATCH 1/3] Fix AggregateFunctionGroupBitmapData bitmapOrCardinality using wrong variable --- .../AggregateFunctionGroupBitmapData.h | 3 +- .../0_stateless/00829_bitmap_function.sql | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/AggregateFunctions/AggregateFunctionGroupBitmapData.h b/src/AggregateFunctions/AggregateFunctionGroupBitmapData.h index 5bca64095fa..596b693babf 100644 --- a/src/AggregateFunctions/AggregateFunctionGroupBitmapData.h +++ b/src/AggregateFunctions/AggregateFunctionGroupBitmapData.h @@ -262,9 +262,10 @@ public: } else if (isSmall() && r1.isLarge()) { + const auto & new_rb = r1.rb; for (const auto & x : small) { - if (rb->contains(static_cast(x.getValue()))) + if (new_rb->contains(static_cast(x.getValue()))) ++ret; } } diff --git a/tests/queries/0_stateless/00829_bitmap_function.sql b/tests/queries/0_stateless/00829_bitmap_function.sql index 1217fbefc71..05d5b64741c 100644 --- a/tests/queries/0_stateless/00829_bitmap_function.sql +++ b/tests/queries/0_stateless/00829_bitmap_function.sql @@ -309,3 +309,40 @@ select bitmapMax(bitmapBuild([1,5,7,9])); select bitmapMax(bitmapBuild([ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33, 100,200,500])); + + +-- reproduce #18911 +CREATE TABLE bitmap_test(pickup_date Date, city_id UInt32, uid UInt32)ENGINE = Memory; +INSERT INTO bitmap_test SELECT '2019-01-01', 1, number FROM numbers(1,50); +INSERT INTO bitmap_test SELECT '2019-01-02', 1, number FROM numbers(11,60); +INSERT INTO bitmap_test SELECT '2019-01-03', 2, number FROM numbers(1,10); + +SELECT + bitmapCardinality(day_today) AS today_users, + bitmapCardinality(day_before) AS before_users, + bitmapOrCardinality(day_today, day_before) AS all_users, + bitmapAndCardinality(day_today, day_before) AS old_users, + bitmapAndnotCardinality(day_today, day_before) AS new_users, + bitmapXorCardinality(day_today, day_before) AS diff_users +FROM +( + SELECT + city_id, + groupBitmapState(uid) AS day_today + FROM bitmap_test + WHERE pickup_date = '2019-01-02' + GROUP BY + rand((rand((rand('') % nan) = NULL) % 7) % rand(NULL)), + city_id +) AS js1 +ALL LEFT JOIN +( + SELECT + city_id, + groupBitmapState(uid) AS day_before + FROM bitmap_test + WHERE pickup_date = '2019-01-01' + GROUP BY city_id +) AS js2 USING (city_id) FORMAT Null; + +drop table bitmap_test; \ No newline at end of file From 4865439130e9c672a68d9c036d80ff03b8c04515 Mon Sep 17 00:00:00 2001 From: sundy-li <543950155@qq.com> Date: Mon, 11 Jan 2021 02:07:18 +0000 Subject: [PATCH 2/3] Empty line after sql --- tests/queries/0_stateless/00829_bitmap_function.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/queries/0_stateless/00829_bitmap_function.sql b/tests/queries/0_stateless/00829_bitmap_function.sql index 05d5b64741c..9ae441b2be7 100644 --- a/tests/queries/0_stateless/00829_bitmap_function.sql +++ b/tests/queries/0_stateless/00829_bitmap_function.sql @@ -345,4 +345,4 @@ ALL LEFT JOIN GROUP BY city_id ) AS js2 USING (city_id) FORMAT Null; -drop table bitmap_test; \ No newline at end of file +drop table bitmap_test; From 9aa7c7ef090aba2ec535ad32fdeebff6fb95a7ad Mon Sep 17 00:00:00 2001 From: sundy-li <543950155@qq.com> Date: Mon, 11 Jan 2021 02:39:02 +0000 Subject: [PATCH 3/3] Fix same bug in another function --- src/AggregateFunctions/AggregateFunctionGroupBitmapData.h | 5 ++--- tests/queries/0_stateless/00829_bitmap_function.sql | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/AggregateFunctions/AggregateFunctionGroupBitmapData.h b/src/AggregateFunctions/AggregateFunctionGroupBitmapData.h index 596b693babf..3acaa29de7e 100644 --- a/src/AggregateFunctions/AggregateFunctionGroupBitmapData.h +++ b/src/AggregateFunctions/AggregateFunctionGroupBitmapData.h @@ -168,7 +168,7 @@ public: { for (const auto & x : small) { - if (rb->contains(static_cast(x.getValue()))) + if (r1.rb->contains(static_cast(x.getValue()))) buffer.push_back(x.getValue()); } @@ -262,10 +262,9 @@ public: } else if (isSmall() && r1.isLarge()) { - const auto & new_rb = r1.rb; for (const auto & x : small) { - if (new_rb->contains(static_cast(x.getValue()))) + if (r1.rb->contains(static_cast(x.getValue()))) ++ret; } } diff --git a/tests/queries/0_stateless/00829_bitmap_function.sql b/tests/queries/0_stateless/00829_bitmap_function.sql index 9ae441b2be7..3ed2ae5530e 100644 --- a/tests/queries/0_stateless/00829_bitmap_function.sql +++ b/tests/queries/0_stateless/00829_bitmap_function.sql @@ -344,5 +344,4 @@ ALL LEFT JOIN WHERE pickup_date = '2019-01-01' GROUP BY city_id ) AS js2 USING (city_id) FORMAT Null; - drop table bitmap_test;