ClickHouse/tests/queries/0_stateless/00652_mutations_alter_update.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

128 lines
5.3 KiB
Bash
Raw Normal View History

2018-09-06 10:49:36 +00:00
#!/usr/bin/env bash
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
2020-12-28 11:46:53 +00:00
# shellcheck source=../shell_config.sh
2020-08-01 00:51:12 +00:00
. "$CURDIR"/../shell_config.sh
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="DROP TABLE IF EXISTS alter_update"
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="CREATE TABLE alter_update \
(d Date, key UInt32, value1 String, value2 UInt64, materialized_value String MATERIALIZED concat('materialized_', toString(value2 + 7))) \
2018-09-06 10:49:36 +00:00
ENGINE MergeTree ORDER BY key PARTITION BY toYYYYMM(d)"
${CLICKHOUSE_CLIENT} --query="SELECT '*** Test expected failures ***'"
${CLICKHOUSE_CLIENT} --query="ALTER TABLE alter_update UPDATE d = today() WHERE 1" 2>/dev/null || echo "Updating partition key should fail"
${CLICKHOUSE_CLIENT} --query="ALTER TABLE alter_update UPDATE key = 1 WHERE 1" 2>/dev/null || echo "Updating primary key should fail"
${CLICKHOUSE_CLIENT} --query="ALTER TABLE alter_update UPDATE materialized_value = 'aaa' WHERE 1" 2>/dev/null || echo "Updating MATERIALIZED column should fail"
${CLICKHOUSE_CLIENT} --query="ALTER TABLE alter_update UPDATE value1 = 'aaa' WHERE 'string'" 2>/dev/null || echo "Updating with non-UInt8 predicate should fail"
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="SELECT '*** Test updating according to a predicate ***'"
${CLICKHOUSE_CLIENT} --query="INSERT INTO alter_update VALUES \
2018-09-06 10:49:36 +00:00
('2000-01-01', 123, 'abc', 1), \
('2000-01-01', 234, 'cde', 2)"
2020-09-03 23:28:44 +00:00
${CLICKHOUSE_CLIENT} --query="ALTER TABLE alter_update UPDATE value1 = 'aaa', value2 = value2 + 100 WHERE key < 200" --mutations_sync=1
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="SELECT * FROM alter_update ORDER BY key"
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="ALTER TABLE alter_update DROP PARTITION 200001"
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="SELECT '*** Test several UPDATE commands with common subexpressions ***'"
${CLICKHOUSE_CLIENT} --query="INSERT INTO alter_update VALUES ('2000-01-01', 123, 'abc', 49)"
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="ALTER TABLE alter_update \
2018-09-06 10:49:36 +00:00
UPDATE value2 = (value2 + 1) / 2 WHERE 1, \
2020-09-03 23:28:44 +00:00
UPDATE value2 = value2 + 1 WHERE 1" --mutations_sync=1
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="SELECT * FROM alter_update ORDER BY key"
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="ALTER TABLE alter_update DROP PARTITION 200001"
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="SELECT '*** Test predicates with IN operator ***'"
${CLICKHOUSE_CLIENT} --query="INSERT INTO alter_update VALUES \
2018-09-06 10:49:36 +00:00
('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 alter_update \
2018-09-06 10:49:36 +00:00
DELETE WHERE key IN (SELECT toUInt32(arrayJoin([121, 122, 123]))), \
UPDATE value1 = concat(value1, 'ccc') WHERE value2 IN (20, 30), \
2020-09-03 23:28:44 +00:00
UPDATE value1 = 'iii' WHERE value2 IN (SELECT toUInt64(40))" --mutations_sync=1
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="SELECT * FROM alter_update ORDER BY key"
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="ALTER TABLE alter_update DROP PARTITION 200001"
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="SELECT '*** Test UPDATE of columns that DELETE depends on ***'"
${CLICKHOUSE_CLIENT} --query="INSERT INTO alter_update VALUES \
2018-09-06 10:49:36 +00:00
('2000-01-01', 123, 'abc', 10), \
('2000-01-01', 234, 'cde', 20)"
${CLICKHOUSE_CLIENT} --query="ALTER TABLE alter_update \
2018-09-06 10:49:36 +00:00
UPDATE value2 = value2 + 10 WHERE 1, \
2020-09-03 23:28:44 +00:00
DELETE WHERE value2 = 20" --mutations_sync=1
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="SELECT * FROM alter_update ORDER BY key"
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="ALTER TABLE alter_update DROP PARTITION 200001"
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="SELECT '*** Test complex mixture of UPDATEs and DELETEs ***'"
${CLICKHOUSE_CLIENT} --query="INSERT INTO alter_update VALUES \
2018-09-06 10:49:36 +00:00
('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 alter_update \
2018-09-06 10:49:36 +00:00
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_37', \
2020-09-03 23:28:44 +00:00
UPDATE value1 = concat(value1, '_', materialized_value) WHERE key = 456" --mutations_sync=1
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="SELECT * FROM alter_update ORDER BY key"
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="ALTER TABLE alter_update DROP PARTITION 200001"
2018-09-06 10:49:36 +00:00
${CLICKHOUSE_CLIENT} --query="SELECT '*** Test updating columns that MATERIALIZED columns depend on ***'"
${CLICKHOUSE_CLIENT} --query="DROP TABLE IF EXISTS materialized_key"
${CLICKHOUSE_CLIENT} --query="CREATE TABLE materialized_key \
(key UInt32 MATERIALIZED value + 1, value UInt32) \
ENGINE MergeTree ORDER BY key"
${CLICKHOUSE_CLIENT} --query="ALTER TABLE materialized_key UPDATE value = 1 WHERE 1" 2>/dev/null || echo "Updating column that MATERIALIZED key column depends on should fail"
${CLICKHOUSE_CLIENT} --query="DROP TABLE materialized_key"
${CLICKHOUSE_CLIENT} --query="INSERT INTO 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 alter_update \
2020-09-03 23:28:44 +00:00
UPDATE value2 = value2 + 7 WHERE value2 <= 20" --mutations_sync=1
${CLICKHOUSE_CLIENT} --query="SELECT value2, materialized_value FROM alter_update ORDER BY key"
${CLICKHOUSE_CLIENT} --query="ALTER TABLE alter_update DROP PARTITION 200001"
${CLICKHOUSE_CLIENT} --query="DROP TABLE alter_update"