From 8cf666e1b538d167ab6f5d5a8b6e2bc64b0aa460 Mon Sep 17 00:00:00 2001 From: Alexey Zatelepin Date: Thu, 6 Sep 2018 13:49:36 +0300 Subject: [PATCH] ALTER UPDATE tests [#CLICKHOUSE-13] --- .../0_stateless/00652_mergetree_mutations.sh | 3 +- .../00652_mutations_alter_update.reference | 18 +++ .../00652_mutations_alter_update.sh | 107 ++++++++++++++++++ .../0_stateless/mergetree_mutations.lib | 2 +- 4 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 dbms/tests/queries/0_stateless/00652_mutations_alter_update.reference create mode 100755 dbms/tests/queries/0_stateless/00652_mutations_alter_update.sh diff --git a/dbms/tests/queries/0_stateless/00652_mergetree_mutations.sh b/dbms/tests/queries/0_stateless/00652_mergetree_mutations.sh index bb29f6d31fe..d762d49a6ce 100755 --- a/dbms/tests/queries/0_stateless/00652_mergetree_mutations.sh +++ b/dbms/tests/queries/0_stateless/00652_mergetree_mutations.sh @@ -43,6 +43,8 @@ ${CLICKHOUSE_CLIENT} --query="SELECT d, x, s, m FROM test.mutations ORDER BY d, ${CLICKHOUSE_CLIENT} --query="SELECT mutation_id, command, block_numbers.partition_id, block_numbers.number, parts_to_do, is_done \ FROM system.mutations WHERE table = 'mutations' ORDER BY mutation_id" +${CLICKHOUSE_CLIENT} --query="DROP TABLE test.mutations" + ${CLICKHOUSE_CLIENT} --query="SELECT '*** Test mutations cleaner ***'" @@ -69,5 +71,4 @@ sleep 0.1 # Check that the first mutation is cleaned ${CLICKHOUSE_CLIENT} --query="SELECT mutation_id, command, is_done FROM system.mutations WHERE table = 'mutations_cleaner' ORDER BY mutation_id" -${CLICKHOUSE_CLIENT} --query="DROP TABLE test.mutations" ${CLICKHOUSE_CLIENT} --query="DROP TABLE test.mutations_cleaner" diff --git a/dbms/tests/queries/0_stateless/00652_mutations_alter_update.reference b/dbms/tests/queries/0_stateless/00652_mutations_alter_update.reference new file mode 100644 index 00000000000..52e57563182 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00652_mutations_alter_update.reference @@ -0,0 +1,18 @@ +*** Test expected failures *** +Updating partition key should fail +Updating primary key should fail +Updating MATERIALIZED column should fail +Updating with non-UInt8 predicate should fail +*** Test updating according to a predicate *** +2000-01-01 123 aaa 101 +2000-01-01 234 cde 2 +*** Test several UPDATE commands with common subexpressions *** +2000-01-01 123 abc 26 +*** Test predicates with IN operator *** +2000-01-01 234 cdeccc 20 +2000-01-01 345 fghccc 30 +2000-01-01 456 iii 40 +*** Test UPDATE of columns that DELETE depends on *** +2000-01-01 234 cde 30 +*** Test complex mixture of UPDATEs and DELETEs *** +2000-01-01 456 ijk_materialized_40 40 diff --git a/dbms/tests/queries/0_stateless/00652_mutations_alter_update.sh b/dbms/tests/queries/0_stateless/00652_mutations_alter_update.sh new file mode 100755 index 00000000000..c85d593dbef --- /dev/null +++ b/dbms/tests/queries/0_stateless/00652_mutations_alter_update.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env bash + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +. $CURDIR/../shell_config.sh + +. $CURDIR/mergetree_mutations.lib + +${CLICKHOUSE_CLIENT} --query="DROP TABLE IF EXISTS test.alter_update" + +${CLICKHOUSE_CLIENT} --query="CREATE TABLE test.alter_update \ + (d Date, key UInt32, value1 String, value2 UInt64, materialized_value String MATERIALIZED concat('materialized_', toString(value2))) \ + ENGINE MergeTree ORDER BY key PARTITION BY toYYYYMM(d)" + + +${CLICKHOUSE_CLIENT} --query="SELECT '*** Test expected failures ***'" + +${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.alter_update UPDATE d = today() WHERE 1" 2>/dev/null || echo "Updating partition key should fail" +${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.alter_update UPDATE key = 1 WHERE 1" 2>/dev/null || echo "Updating primary key should fail" +${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.alter_update UPDATE materialized_value = 'aaa' WHERE 1" 2>/dev/null || echo "Updating MATERIALIZED column should fail" +${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.alter_update UPDATE value1 = 'aaa' WHERE 'string'" 2>/dev/null || echo "Updating with non-UInt8 predicate should fail" + + +${CLICKHOUSE_CLIENT} --query="SELECT '*** Test updating according to a predicate ***'" + +${CLICKHOUSE_CLIENT} --query="INSERT INTO test.alter_update VALUES \ + ('2000-01-01', 123, 'abc', 1), \ + ('2000-01-01', 234, 'cde', 2)" + +${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.alter_update UPDATE value1 = 'aaa', value2 = value2 + 100 WHERE key < 200" +wait_for_mutation "alter_update" "mutation_2.txt" + +${CLICKHOUSE_CLIENT} --query="SELECT * FROM test.alter_update ORDER BY key" + +${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.alter_update DROP PARTITION 200001" + + +${CLICKHOUSE_CLIENT} --query="SELECT '*** Test several UPDATE commands with common subexpressions ***'" + +${CLICKHOUSE_CLIENT} --query="INSERT INTO test.alter_update VALUES ('2000-01-01', 123, 'abc', 49)" + +${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.alter_update \ + UPDATE value2 = (value2 + 1) / 2 WHERE 1, \ + UPDATE value2 = value2 + 1 WHERE 1" +wait_for_mutation "alter_update" "mutation_4.txt" + +${CLICKHOUSE_CLIENT} --query="SELECT * FROM test.alter_update ORDER BY key" + +${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.alter_update DROP PARTITION 200001" + + +${CLICKHOUSE_CLIENT} --query="SELECT '*** Test predicates with IN operator ***'" + +${CLICKHOUSE_CLIENT} --query="INSERT INTO test.alter_update VALUES \ + ('2000-01-01', 123, 'abc', 10), \ + ('2000-01-01', 234, 'cde', 20), \ + ('2000-01-01', 345, 'fgh', 30), \ + ('2000-01-01', 456, 'ijk', 40)" + +${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.alter_update \ + DELETE WHERE key IN (SELECT toUInt32(arrayJoin([121, 122, 123]))), \ + UPDATE value1 = concat(value1, 'ccc') WHERE value2 IN (20, 30), \ + UPDATE value1 = 'iii' WHERE value2 IN (SELECT toUInt64(40))" +wait_for_mutation "alter_update" "mutation_6.txt" + +${CLICKHOUSE_CLIENT} --query="SELECT * FROM test.alter_update ORDER BY key" + +${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.alter_update DROP PARTITION 200001" + + +${CLICKHOUSE_CLIENT} --query="SELECT '*** Test UPDATE of columns that DELETE depends on ***'" + +${CLICKHOUSE_CLIENT} --query="INSERT INTO test.alter_update VALUES \ + ('2000-01-01', 123, 'abc', 10), \ + ('2000-01-01', 234, 'cde', 20)" + +${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.alter_update \ + UPDATE value2 = value2 + 10 WHERE 1, \ + DELETE WHERE value2 = 20" +wait_for_mutation "alter_update" "mutation_8.txt" + +${CLICKHOUSE_CLIENT} --query="SELECT * FROM test.alter_update ORDER BY key" + +${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.alter_update DROP PARTITION 200001" + + +${CLICKHOUSE_CLIENT} --query="SELECT '*** Test complex mixture of UPDATEs and DELETEs ***'" + +${CLICKHOUSE_CLIENT} --query="INSERT INTO test.alter_update VALUES \ + ('2000-01-01', 123, 'abc', 10), \ + ('2000-01-01', 234, 'cde', 20), \ + ('2000-01-01', 345, 'fgh', 30), \ + ('2000-01-01', 456, 'ijk', 40)" + +${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.alter_update \ + DELETE WHERE value2 IN (8, 9, 10), \ + UPDATE value2 = value2 + 10 WHERE value2 <= 10, \ + DELETE WHERE length(value1) + value2 = 23, \ + DELETE WHERE materialized_value = 'materialized_30', \ + UPDATE value1 = concat(value1, '_', materialized_value) WHERE key = 456" +wait_for_mutation "alter_update" "mutation_10.txt" + +${CLICKHOUSE_CLIENT} --query="SELECT * FROM test.alter_update ORDER BY key" + +${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.alter_update DROP PARTITION 200001" + + +${CLICKHOUSE_CLIENT} --query="DROP TABLE test.alter_update" diff --git a/dbms/tests/queries/0_stateless/mergetree_mutations.lib b/dbms/tests/queries/0_stateless/mergetree_mutations.lib index 0df275092fe..eb2f4030eba 100644 --- a/dbms/tests/queries/0_stateless/mergetree_mutations.lib +++ b/dbms/tests/queries/0_stateless/mergetree_mutations.lib @@ -8,7 +8,7 @@ function wait_for_mutation() for i in {1..100} do sleep 0.1 - if [[ $(${CLICKHOUSE_CLIENT} --query="SELECT is_done FROM system.mutations WHERE table='$table' AND mutation_id='$mutation_id'") -eq 1 ]]; then + if [[ $(${CLICKHOUSE_CLIENT} --query="SELECT min(is_done) FROM system.mutations WHERE table='$table' AND mutation_id='$mutation_id'") -eq 1 ]]; then break fi