ClickHouse/tests/queries/0_stateless/01155_rename_move_materialized_view.sql

89 lines
4.5 KiB
MySQL
Raw Normal View History

2021-09-12 12:35:27 +00:00
-- Tags: no-parallel
2021-05-19 18:53:31 +00:00
DROP DATABASE IF EXISTS test_01155_ordinary;
DROP DATABASE IF EXISTS test_01155_atomic;
CREATE DATABASE test_01155_ordinary ENGINE=Ordinary;
CREATE DATABASE test_01155_atomic ENGINE=Atomic;
USE test_01155_ordinary;
2021-11-22 15:41:35 +00:00
CREATE TABLE src (s String, x String DEFAULT 'a') ENGINE=MergeTree() PARTITION BY tuple() ORDER BY s;
CREATE MATERIALIZED VIEW mv1 (s String, x String DEFAULT 'b') ENGINE=MergeTree() PARTITION BY tuple() ORDER BY s AS SELECT (*,).1 || 'mv1' as s FROM src;
CREATE TABLE dst (s String, x String DEFAULT 'c') ENGINE=MergeTree() PARTITION BY tuple() ORDER BY s;
CREATE MATERIALIZED VIEW mv2 TO dst (s String, x String DEFAULT 'd') AS SELECT (*,).1 || 'mv2' as s FROM src;
CREATE TABLE dist (s String, x String DEFAULT 'asdf') ENGINE=Distributed(test_shard_localhost, test_01155_ordinary, src);
INSERT INTO dist(s) VALUES ('before moving tables');
2021-06-24 10:00:33 +00:00
SYSTEM FLUSH DISTRIBUTED dist;
2021-11-22 15:41:35 +00:00
CREATE DICTIONARY dict (s String, x String DEFAULT 'qwerty') PRIMARY KEY s
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'dist' DB 'test_01155_ordinary'))
LIFETIME(MIN 0 MAX 2) LAYOUT(COMPLEX_KEY_CACHE(SIZE_IN_CELLS 123));
2021-06-24 10:00:33 +00:00
-- FIXME Cannot convert column `1` because it is non constant in source stream but must be constant in result
SELECT materialize(1), substr(_table, 1, 10), s FROM merge('test_01155_ordinary', '') ORDER BY _table, s;
2021-11-22 15:41:35 +00:00
SELECT dictGet('test_01155_ordinary.dict', 'x', 'before moving tables');
2021-05-19 18:53:31 +00:00
RENAME DICTIONARY test_01155_ordinary.dict TO test_01155_ordinary.dict1;
SELECT dictGet('test_01155_ordinary.dict1', 'x', 'before moving tables');
SELECT database, name, uuid FROM system.dictionaries WHERE database='test_01155_ordinary';
RENAME TABLE test_01155_ordinary.dict1 TO test_01155_ordinary.dict;
SELECT dictGet('test_01155_ordinary.dict', 'x', 'before moving tables');
2021-05-19 18:53:31 +00:00
-- Move tables with materialized views from Ordinary to Atomic
SELECT 'ordinary:';
SHOW TABLES FROM test_01155_ordinary;
RENAME TABLE test_01155_ordinary.mv1 TO test_01155_atomic.mv1;
RENAME TABLE test_01155_ordinary.mv2 TO test_01155_atomic.mv2;
RENAME TABLE test_01155_ordinary.dst TO test_01155_atomic.dst;
RENAME TABLE test_01155_ordinary.src TO test_01155_atomic.src;
2021-11-22 15:41:35 +00:00
SET check_table_dependencies=0;
2021-06-24 10:00:33 +00:00
RENAME TABLE test_01155_ordinary.dist TO test_01155_atomic.dist;
2021-11-22 15:41:35 +00:00
SET check_table_dependencies=1;
RENAME DICTIONARY test_01155_ordinary.dict TO test_01155_atomic.dict;
2021-05-19 18:53:31 +00:00
SELECT 'ordinary after rename:';
SELECT substr(name, 1, 10) FROM system.tables WHERE database='test_01155_ordinary';
SELECT 'atomic after rename:';
SELECT substr(name, 1, 10) FROM system.tables WHERE database='test_01155_atomic';
DROP DATABASE test_01155_ordinary;
USE default;
2021-11-22 15:41:35 +00:00
INSERT INTO test_01155_atomic.src(s) VALUES ('after moving tables');
SELECT materialize(2), substr(_table, 1, 10), s FROM merge('test_01155_atomic', '') ORDER BY _table, s; -- { serverError 81 }
SELECT dictGet('test_01155_ordinary.dict', 'x', 'after moving tables'); -- { serverError 36 }
2021-05-19 18:53:31 +00:00
RENAME DATABASE test_01155_atomic TO test_01155_ordinary;
USE test_01155_ordinary;
2021-11-22 15:41:35 +00:00
INSERT INTO dist(s) VALUES ('after renaming database');
2021-06-24 10:00:33 +00:00
SYSTEM FLUSH DISTRIBUTED dist;
SELECT materialize(3), substr(_table, 1, 10), s FROM merge('test_01155_ordinary', '') ORDER BY _table, s;
2021-11-22 15:41:35 +00:00
SELECT dictGet('test_01155_ordinary.dict', 'x', 'after renaming database');
2021-05-19 18:53:31 +00:00
2021-11-22 15:41:35 +00:00
SELECT database, substr(name, 1, 10) FROM system.tables WHERE database like 'test_01155_%';
2021-05-19 18:53:31 +00:00
-- Move tables back
RENAME DATABASE test_01155_ordinary TO test_01155_atomic;
CREATE DATABASE test_01155_ordinary ENGINE=Ordinary;
SHOW CREATE DATABASE test_01155_atomic;
RENAME TABLE test_01155_atomic.mv1 TO test_01155_ordinary.mv1;
RENAME TABLE test_01155_atomic.mv2 TO test_01155_ordinary.mv2;
RENAME TABLE test_01155_atomic.dst TO test_01155_ordinary.dst;
RENAME TABLE test_01155_atomic.src TO test_01155_ordinary.src;
2021-06-24 10:00:33 +00:00
RENAME TABLE test_01155_atomic.dist TO test_01155_ordinary.dist;
2021-11-22 15:41:35 +00:00
RENAME DICTIONARY test_01155_atomic.dict TO test_01155_ordinary.dict;
2021-05-19 18:53:31 +00:00
2021-11-22 15:41:35 +00:00
INSERT INTO dist(s) VALUES ('after renaming tables');
2021-06-24 10:00:33 +00:00
SYSTEM FLUSH DISTRIBUTED dist;
SELECT materialize(4), substr(_table, 1, 10), s FROM merge('test_01155_ordinary', '') ORDER BY _table, s;
2021-11-22 15:41:35 +00:00
SELECT dictGet('test_01155_ordinary.dict', 'x', 'after renaming tables');
SELECT database, name, uuid FROM system.dictionaries WHERE database='test_01155_ordinary';
2021-05-19 18:53:31 +00:00
SELECT 'test_01155_ordinary:';
SHOW TABLES FROM test_01155_ordinary;
SELECT 'test_01155_atomic:';
SHOW TABLES FROM test_01155_atomic;
DROP DATABASE IF EXISTS test_01155_atomic;
DROP DATABASE IF EXISTS test_01155_ordinary;