2020-01-05 19:36:14 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
2020-08-12 08:55:04 +00:00
|
|
|
node = cluster.add_instance('node', main_configs=['configs/remote_servers.xml'])
|
2020-01-05 19:36:14 +00:00
|
|
|
|
2020-06-08 19:15:30 +00:00
|
|
|
cluster_param = pytest.mark.parametrize("cluster", [
|
|
|
|
('test_cluster'),
|
|
|
|
('test_cluster_2'),
|
|
|
|
])
|
|
|
|
|
2020-01-05 19:36:14 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def started_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
2020-09-22 11:56:40 +00:00
|
|
|
node.query("create database test")
|
2020-01-05 19:36:14 +00:00
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2020-06-08 19:15:30 +00:00
|
|
|
@cluster_param
|
|
|
|
def test_single_file(started_cluster, cluster):
|
2020-09-16 04:26:10 +00:00
|
|
|
node.query(
|
|
|
|
"create table test.distr_1 (x UInt64, s String) engine = Distributed('{}', database, table)".format(cluster))
|
|
|
|
node.query("insert into test.distr_1 values (1, 'a'), (2, 'bb'), (3, 'ccc')",
|
|
|
|
settings={"use_compact_format_in_distributed_parts_names": "1"})
|
2020-01-05 19:36:14 +00:00
|
|
|
|
2020-03-16 11:38:50 +00:00
|
|
|
query = "select * from file('/var/lib/clickhouse/data/test/distr_1/shard1_replica1/1.bin', 'Distributed')"
|
2020-01-05 19:36:14 +00:00
|
|
|
out = node.exec_in_container(['/usr/bin/clickhouse', 'local', '--stacktrace', '-q', query])
|
|
|
|
|
|
|
|
assert out == '1\ta\n2\tbb\n3\tccc\n'
|
|
|
|
|
2020-10-14 12:19:29 +00:00
|
|
|
query = "create table t (x UInt64, s String) engine = File('Distributed', '/var/lib/clickhouse/data/test/distr_1/shard1_replica1/1.bin');" \
|
2020-01-05 19:36:14 +00:00
|
|
|
"select * from t"
|
|
|
|
out = node.exec_in_container(['/usr/bin/clickhouse', 'local', '--stacktrace', '-q', query])
|
|
|
|
|
|
|
|
assert out == '1\ta\n2\tbb\n3\tccc\n'
|
|
|
|
|
2020-01-28 19:39:52 +00:00
|
|
|
node.query("drop table test.distr_1")
|
2020-01-05 19:36:14 +00:00
|
|
|
|
|
|
|
|
2020-06-08 19:15:30 +00:00
|
|
|
@cluster_param
|
|
|
|
def test_two_files(started_cluster, cluster):
|
2020-09-16 04:26:10 +00:00
|
|
|
node.query(
|
|
|
|
"create table test.distr_2 (x UInt64, s String) engine = Distributed('{}', database, table)".format(cluster))
|
|
|
|
node.query("insert into test.distr_2 values (0, '_'), (1, 'a')",
|
|
|
|
settings={"use_compact_format_in_distributed_parts_names": "1"})
|
|
|
|
node.query("insert into test.distr_2 values (2, 'bb'), (3, 'ccc')",
|
|
|
|
settings={"use_compact_format_in_distributed_parts_names": "1"})
|
2020-01-05 19:36:14 +00:00
|
|
|
|
2020-03-16 11:38:50 +00:00
|
|
|
query = "select * from file('/var/lib/clickhouse/data/test/distr_2/shard1_replica1/{1,2,3,4}.bin', 'Distributed') order by x"
|
2020-01-05 19:36:14 +00:00
|
|
|
out = node.exec_in_container(['/usr/bin/clickhouse', 'local', '--stacktrace', '-q', query])
|
|
|
|
|
|
|
|
assert out == '0\t_\n1\ta\n2\tbb\n3\tccc\n'
|
|
|
|
|
2020-10-14 12:19:29 +00:00
|
|
|
query = "create table t (x UInt64, s String) engine = File('Distributed', '/var/lib/clickhouse/data/test/distr_2/shard1_replica1/{1,2,3,4}.bin');" \
|
2020-01-05 19:36:14 +00:00
|
|
|
"select * from t order by x"
|
|
|
|
out = node.exec_in_container(['/usr/bin/clickhouse', 'local', '--stacktrace', '-q', query])
|
|
|
|
|
|
|
|
assert out == '0\t_\n1\ta\n2\tbb\n3\tccc\n'
|
|
|
|
|
2020-01-28 19:39:52 +00:00
|
|
|
node.query("drop table test.distr_2")
|
2020-03-13 18:49:46 +00:00
|
|
|
|
|
|
|
|
2020-06-08 19:15:30 +00:00
|
|
|
@cluster_param
|
|
|
|
def test_single_file_old(started_cluster, cluster):
|
2020-09-16 04:26:10 +00:00
|
|
|
node.query(
|
|
|
|
"create table test.distr_3 (x UInt64, s String) engine = Distributed('{}', database, table)".format(cluster))
|
2020-03-18 17:38:52 +00:00
|
|
|
node.query("insert into test.distr_3 values (1, 'a'), (2, 'bb'), (3, 'ccc')")
|
2020-03-13 18:49:46 +00:00
|
|
|
|
2020-03-18 17:38:52 +00:00
|
|
|
query = "select * from file('/var/lib/clickhouse/data/test/distr_3/default@not_existing:9000/1.bin', 'Distributed')"
|
2020-03-13 18:49:46 +00:00
|
|
|
out = node.exec_in_container(['/usr/bin/clickhouse', 'local', '--stacktrace', '-q', query])
|
|
|
|
|
|
|
|
assert out == '1\ta\n2\tbb\n3\tccc\n'
|
|
|
|
|
2020-10-14 12:19:29 +00:00
|
|
|
query = "create table t (x UInt64, s String) engine = File('Distributed', '/var/lib/clickhouse/data/test/distr_3/default@not_existing:9000/1.bin');" \
|
2020-03-13 18:49:46 +00:00
|
|
|
"select * from t"
|
|
|
|
out = node.exec_in_container(['/usr/bin/clickhouse', 'local', '--stacktrace', '-q', query])
|
|
|
|
|
|
|
|
assert out == '1\ta\n2\tbb\n3\tccc\n'
|
|
|
|
|
2020-03-18 17:38:52 +00:00
|
|
|
node.query("drop table test.distr_3")
|