2021-10-04 14:27:44 +00:00
|
|
|
import pytest
|
|
|
|
|
2024-09-27 10:19:39 +00:00
|
|
|
from helpers.cluster import CLICKHOUSE_CI_MIN_TESTED_VERSION, ClickHouseCluster
|
2021-10-04 14:27:44 +00:00
|
|
|
|
2022-07-18 12:25:14 +00:00
|
|
|
cluster = ClickHouseCluster(__file__)
|
2021-10-22 13:32:49 +00:00
|
|
|
node1 = cluster.add_instance(
|
|
|
|
"node1",
|
|
|
|
with_zookeeper=True,
|
2024-02-26 12:45:20 +00:00
|
|
|
image="clickhouse/clickhouse-server",
|
|
|
|
tag=CLICKHOUSE_CI_MIN_TESTED_VERSION,
|
2021-10-22 13:32:49 +00:00
|
|
|
with_installed_binary=True,
|
|
|
|
)
|
2024-03-20 12:43:18 +00:00
|
|
|
node2 = cluster.add_instance("node2", with_zookeeper=True, use_old_analyzer=True)
|
|
|
|
node3 = cluster.add_instance("node3", with_zookeeper=True, use_old_analyzer=True)
|
2021-10-04 14:27:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def start_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
def test_two_level_merge(start_cluster):
|
|
|
|
for node in start_cluster.instances.values():
|
|
|
|
node.query(
|
|
|
|
"""
|
|
|
|
CREATE TABLE IF NOT EXISTS test_two_level_merge(date Date, zone UInt32, number UInt32)
|
|
|
|
ENGINE = MergeTree() PARTITION BY toUInt64(number / 1000) ORDER BY tuple();
|
|
|
|
|
|
|
|
INSERT INTO
|
|
|
|
test_two_level_merge
|
|
|
|
SELECT
|
|
|
|
toDate('2021-09-28') - number / 1000,
|
|
|
|
249081628,
|
|
|
|
number
|
|
|
|
FROM
|
|
|
|
numbers(15000);
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
|
|
|
# covers only the keys64 method
|
|
|
|
for node in start_cluster.instances.values():
|
|
|
|
print(
|
|
|
|
node.query(
|
|
|
|
"""
|
|
|
|
SELECT
|
|
|
|
throwIf(uniqExact(date) != count(), 'group by is borked')
|
|
|
|
FROM (
|
|
|
|
SELECT
|
|
|
|
date
|
|
|
|
FROM
|
|
|
|
remote('node{1,2}', default.test_two_level_merge)
|
|
|
|
WHERE
|
|
|
|
date BETWEEN toDate('2021-09-20') AND toDate('2021-09-28')
|
|
|
|
AND zone = 249081628
|
|
|
|
GROUP by date, zone
|
|
|
|
)
|
|
|
|
SETTINGS
|
|
|
|
group_by_two_level_threshold = 1,
|
|
|
|
group_by_two_level_threshold_bytes = 1,
|
|
|
|
max_threads = 2,
|
|
|
|
prefer_localhost_replica = 0
|
|
|
|
"""
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|