This commit is contained in:
Alexander Tokmakov 2020-04-09 21:02:27 +03:00
parent 140cd88c20
commit a6d0aacd53

View File

@ -19,31 +19,47 @@ def start_cluster():
finally: finally:
cluster.shutdown() cluster.shutdown()
def get_counts():
src = int(node.query("SELECT count() FROM test"))
a = int(node.query("SELECT count() FROM test_mv_a"))
b = int(node.query("SELECT count() FROM test_mv_b"))
c = int(node.query("SELECT count() FROM test_mv_c"))
return src, a, b, c
def test_basic(start_cluster): def test_basic(start_cluster):
node.query(
'''
CREATE TABLE test (A Int64) ENGINE = ReplicatedMergeTree ('/clickhouse/test/tables/test','1') ORDER BY tuple();
CREATE MATERIALIZED VIEW test_mv_a Engine=ReplicatedMergeTree ('/clickhouse/test/tables/test_mv_a','1') order by tuple() AS SELECT A FROM test;
CREATE MATERIALIZED VIEW test_mv_b Engine=ReplicatedMergeTree ('/clickhouse/test/tables/test_mv_b','1') partition by A order by tuple() AS SELECT A FROM test;
CREATE MATERIALIZED VIEW test_mv_c Engine=ReplicatedMergeTree ('/clickhouse/test/tables/test_mv_c','1') order by tuple() AS SELECT A FROM test;
INSERT INTO test values(999);
INSERT INTO test values(999);
'''
)
with pytest.raises(QueryRuntimeException): with pytest.raises(QueryRuntimeException):
node.query( node.query(
''' '''
CREATE TABLE test (A Int64) ENGINE = ReplicatedMergeTree ('/clickhouse/test/tables/test','1') ORDER BY tuple();
CREATE MATERIALIZED VIEW test_mv_a Engine=ReplicatedMergeTree ('/clickhouse/test/tables/test_mv_a','1') order by tuple() AS SELECT A FROM test;
CREATE MATERIALIZED VIEW test_mv_b Engine=ReplicatedMergeTree ('/clickhouse/test/tables/test_mv_b','1') partition by A order by tuple() AS SELECT A FROM test;
CREATE MATERIALIZED VIEW test_mv_c Engine=ReplicatedMergeTree ('/clickhouse/test/tables/test_mv_c','1') order by tuple() AS SELECT A FROM test;
INSERT INTO test values(999);
INSERT INTO test values(999);
SET max_partitions_per_insert_block = 3; SET max_partitions_per_insert_block = 3;
INSERT INTO test SELECT number FROM numbers(10); INSERT INTO test SELECT number FROM numbers(10);
''' '''
) )
assert int(node.query("SELECT count() FROM test")) == 11 old_src, old_a, old_b, old_c = get_counts()
assert int(node.query("SELECT count() FROM test_mv_a")) == 11 # number of rows in test_mv_a and test_mv_c depends on order of inserts into views
assert int(node.query("SELECT count() FROM test_mv_b")) == 1 assert old_src == 11
assert int(node.query("SELECT count() FROM test_mv_c")) == 1 assert old_a in (1, 11)
assert old_b == 1
assert old_c in (1, 11)
node.query("INSERT INTO test SELECT number FROM numbers(10)") node.query("INSERT INTO test SELECT number FROM numbers(10)")
assert int(node.query("SELECT count() FROM test")) == 11 src, a, b, c = get_counts()
assert int(node.query("SELECT count() FROM test_mv_a")) == 11 # no changes because of deduplication in source table
assert int(node.query("SELECT count() FROM test_mv_b")) == 1 assert src == old_src
assert int(node.query("SELECT count() FROM test_mv_c")) == 1 assert a == old_a
assert b == old_b
assert c == old_c
node.query( node.query(
''' '''
@ -51,10 +67,11 @@ def test_basic(start_cluster):
INSERT INTO test SELECT number FROM numbers(10); INSERT INTO test SELECT number FROM numbers(10);
''' '''
) )
assert int(node.query("SELECT count() FROM test")) == 11 src, a, b, c = get_counts()
assert int(node.query("SELECT count() FROM test_mv_a")) == 21 # first insert was succesfull with disabled dedup.. assert src == 11
assert int(node.query("SELECT count() FROM test_mv_b")) == 11 assert a == old_a + 10 # first insert could be succesfull with disabled dedup
assert int(node.query("SELECT count() FROM test_mv_c")) == 11 assert b == 11
assert c == old_c + 10
with pytest.raises(QueryRuntimeException): with pytest.raises(QueryRuntimeException):
node.query( node.query(
@ -71,8 +88,11 @@ def test_basic(start_cluster):
INSERT INTO test SELECT number FROM numbers(100,10); INSERT INTO test SELECT number FROM numbers(100,10);
''' '''
) )
assert int(node.query("SELECT count() FROM test")) == 21 src, a, b, c = get_counts()
assert int(node.query("SELECT count() FROM test_mv_a")) == 31 assert src == 21
assert int(node.query("SELECT count() FROM test_mv_b")) == 21 assert a == old_a + 20
assert int(node.query("SELECT count() FROM test_mv_c")) == 21 assert b == 21
assert c == old_c + 20