2021-12-17 14:50:41 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2021-12-17 14:50:41 +00:00
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
node1 = cluster.add_instance(
|
2023-08-07 15:49:34 +00:00
|
|
|
"node1",
|
|
|
|
main_configs=["configs/clusters.xml"],
|
|
|
|
with_zookeeper=True,
|
|
|
|
allow_analyzer=False,
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
|
|
|
node2 = cluster.add_instance(
|
2023-08-07 15:49:34 +00:00
|
|
|
"node2",
|
|
|
|
main_configs=["configs/clusters.xml"],
|
|
|
|
with_zookeeper=True,
|
|
|
|
allow_analyzer=False,
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
|
|
|
|
2021-12-17 14:50:41 +00:00
|
|
|
|
|
|
|
def insert_data(node, table_name):
|
2022-03-22 16:39:58 +00:00
|
|
|
node.query(
|
|
|
|
"""INSERT INTO {}
|
|
|
|
VALUES (bitmapBuild(cast([1,2,3,4,5,6,7,8,9,10] as Array(UInt32))));""".format(
|
|
|
|
table_name
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2021-12-17 14:50:41 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def start_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
yield cluster
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
def test_groupBitmapAnd_on_distributed_table(start_cluster):
|
|
|
|
local_table_name = "bitmap_column_expr_test"
|
|
|
|
distributed_table_name = "bitmap_column_expr_test_dst"
|
2021-12-18 05:35:36 +00:00
|
|
|
cluster_name = "awesome_cluster"
|
2021-12-17 14:50:41 +00:00
|
|
|
|
2021-12-17 23:55:12 +00:00
|
|
|
for node in (node1, node2):
|
2022-03-22 16:39:58 +00:00
|
|
|
node.query(
|
|
|
|
"""CREATE TABLE {}
|
2021-12-17 23:55:12 +00:00
|
|
|
(
|
|
|
|
z AggregateFunction(groupBitmap, UInt32)
|
|
|
|
)
|
|
|
|
ENGINE = MergeTree()
|
2022-03-22 16:39:58 +00:00
|
|
|
ORDER BY tuple()""".format(
|
|
|
|
local_table_name
|
|
|
|
)
|
|
|
|
)
|
2021-12-17 23:55:12 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
node.query(
|
|
|
|
"""CREATE TABLE {}
|
2021-12-17 23:55:12 +00:00
|
|
|
(
|
|
|
|
z AggregateFunction(groupBitmap, UInt32)
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
ENGINE = Distributed('{}', 'default', '{}')""".format(
|
|
|
|
distributed_table_name, cluster_name, local_table_name
|
|
|
|
)
|
|
|
|
)
|
2021-12-17 14:50:41 +00:00
|
|
|
insert_data(node1, local_table_name)
|
|
|
|
|
|
|
|
expected = "10"
|
2021-12-17 23:55:12 +00:00
|
|
|
|
|
|
|
for node in (node1, node2):
|
2022-03-22 16:39:58 +00:00
|
|
|
result = node.query(
|
|
|
|
"select groupBitmapAnd(z) FROM {};".format(distributed_table_name)
|
|
|
|
).strip()
|
|
|
|
assert result == expected
|