This commit is contained in:
Michael Kolupaev 2014-07-14 20:01:23 +04:00
commit 8eb2a7218b
4 changed files with 161 additions and 14 deletions

View File

@ -131,7 +131,13 @@ StoragePtr InterpreterCreateQuery::execute(bool assume_metadata_exists)
/// Даже если в запросе был список столбцов, на всякий случай приведем его к стандартному виду (развернем Nested).
ASTPtr new_columns = formatColumns(*columns);
if (create.columns)
*std::find(create.children.begin(), create.children.end(), create.columns) = new_columns;
{
auto it = std::find(create.children.begin(), create.children.end(), create.columns);
if (it != create.children.end())
*it = new_columns;
else
create.children.push_back(new_columns);
}
else
create.children.push_back(new_columns);
create.columns = new_columns;

View File

@ -39,6 +39,7 @@ StorageMaterializedView::StorageMaterializedView(const String & table_name_, con
manual_create_query->database = database_name;
manual_create_query->table = getInnerTableName();
manual_create_query->columns = create.columns;
manual_create_query->children.push_back(manual_create_query->columns);
ASTPtr ast_create_query = manual_create_query;
/// Если не указан в запросе тип хранилища попробовать извлечь его из запроса Select.
@ -52,6 +53,8 @@ StorageMaterializedView::StorageMaterializedView(const String & table_name_, con
else
manual_create_query->storage = create.inner_storage;
manual_create_query->children.push_back(manual_create_query->storage);
/// Выполним запрос.
InterpreterCreateQuery create_interpreter(ast_create_query, context);
data = create_interpreter.execute();

View File

@ -0,0 +1,138 @@
d Date
k UInt64
i32 Int32
CREATE TABLE test.alter ( d Date, k UInt64, i32 Int32) ENGINE = MergeTree(d, k, 8192)
2015-01-01 10 42
d Date
k UInt64
i32 Int32
dt DateTime
CREATE TABLE test.alter ( d Date, k UInt64, i32 Int32, dt DateTime) ENGINE = MergeTree(d, k, 8192)
2015-01-01 9 41 1992-01-01 08:00:00
2015-01-01 10 42 0000-00-00 00:00:00
d Date
k UInt64
i32 Int32
dt DateTime
n.ui8 Array(UInt8)
n.s Array(String)
CREATE TABLE test.alter ( d Date, k UInt64, i32 Int32, dt DateTime, `n.ui8` Array(UInt8), `n.s` Array(String)) ENGINE = MergeTree(d, k, 8192)
2015-01-01 8 40 2012-12-12 12:12:12 [1,2,3] ['12','13','14']
2015-01-01 9 41 1992-01-01 08:00:00 [] []
2015-01-01 10 42 0000-00-00 00:00:00 [] []
d Date
k UInt64
i32 Int32
dt DateTime
n.ui8 Array(UInt8)
n.s Array(String)
n.d Array(Date)
CREATE TABLE test.alter ( d Date, k UInt64, i32 Int32, dt DateTime, `n.ui8` Array(UInt8), `n.s` Array(String), `n.d` Array(Date)) ENGINE = MergeTree(d, k, 8192)
2015-01-01 7 39 2014-07-14 13:26:50 [10,20,30] ['120','130','140'] ['2000-01-01','2000-01-01','2000-01-03']
2015-01-01 8 40 2012-12-12 12:12:12 [1,2,3] ['12','13','14'] ['0000-00-00','0000-00-00','0000-00-00']
2015-01-01 9 41 1992-01-01 08:00:00 [] [] []
2015-01-01 10 42 0000-00-00 00:00:00 [] [] []
d Date
k UInt64
i32 Int32
dt DateTime
n.ui8 Array(UInt8)
n.s Array(String)
n.d Array(Date)
s String
CREATE TABLE test.alter ( d Date, k UInt64, i32 Int32, dt DateTime, `n.ui8` Array(UInt8), `n.s` Array(String), `n.d` Array(Date), s String) ENGINE = MergeTree(d, k, 8192)
2015-01-01 6 38 2014-07-15 13:26:50 [10,20,30] ['asd','qwe','qwe'] ['2000-01-01','2000-01-01','2000-01-03'] 100500
2015-01-01 7 39 2014-07-14 13:26:50 [10,20,30] ['120','130','140'] ['2000-01-01','2000-01-01','2000-01-03']
2015-01-01 8 40 2012-12-12 12:12:12 [1,2,3] ['12','13','14'] ['0000-00-00','0000-00-00','0000-00-00']
2015-01-01 9 41 1992-01-01 08:00:00 [] [] []
2015-01-01 10 42 0000-00-00 00:00:00 [] [] []
d Date
k UInt64
i32 Int32
dt DateTime
n.ui8 Array(UInt8)
n.s Array(String)
s Int64
CREATE TABLE test.alter ( d Date, k UInt64, i32 Int32, dt DateTime, `n.ui8` Array(UInt8), `n.s` Array(String), s Int64) ENGINE = MergeTree(d, k, 8192)
2015-01-01 6 38 2014-07-15 13:26:50 [10,20,30] ['asd','qwe','qwe'] 100500
2015-01-01 7 39 2014-07-14 13:26:50 [10,20,30] ['120','130','140'] 0
2015-01-01 8 40 2012-12-12 12:12:12 [1,2,3] ['12','13','14'] 0
2015-01-01 9 41 1992-01-01 08:00:00 [] [] 0
2015-01-01 10 42 0000-00-00 00:00:00 [] [] 0
d Date
k UInt64
i32 Int32
dt DateTime
n.ui8 Array(UInt8)
n.s Array(String)
s UInt32
n.d Array(Date)
CREATE TABLE test.alter ( d Date, k UInt64, i32 Int32, dt DateTime, `n.ui8` Array(UInt8), `n.s` Array(String), s UInt32, `n.d` Array(Date)) ENGINE = MergeTree(d, k, 8192)
2015-01-01 6 38 2014-07-15 13:26:50 [10,20,30] ['asd','qwe','qwe'] 100500 ['0000-00-00','0000-00-00','0000-00-00']
2015-01-01 7 39 2014-07-14 13:26:50 [10,20,30] ['120','130','140'] 0 ['0000-00-00','0000-00-00','0000-00-00']
2015-01-01 8 40 2012-12-12 12:12:12 [1,2,3] ['12','13','14'] 0 ['0000-00-00','0000-00-00','0000-00-00']
2015-01-01 9 41 1992-01-01 08:00:00 [] [] 0 []
2015-01-01 10 42 0000-00-00 00:00:00 [] [] 0 []
2015-01-01 6 38 2014-07-15 13:26:50 [10,20,30] ['asd','qwe','qwe'] 100500 ['0000-00-00','0000-00-00','0000-00-00']
2015-01-01 7 39 2014-07-14 13:26:50 [10,20,30] ['120','130','140'] 0 ['0000-00-00','0000-00-00','0000-00-00']
2015-01-01 8 40 2012-12-12 12:12:12 [1,2,3] ['12','13','14'] 0 ['0000-00-00','0000-00-00','0000-00-00']
2015-01-01 9 41 1992-01-01 08:00:00 [] [] 0 []
2015-01-01 10 42 0000-00-00 00:00:00 [] [] 0 []
d Date
k UInt64
i32 Int32
dt DateTime
n.s Array(String)
s UInt32
CREATE TABLE test.alter ( d Date, k UInt64, i32 Int32, dt DateTime, `n.s` Array(String), s UInt32) ENGINE = MergeTree(d, k, 8192)
2015-01-01 6 38 2014-07-15 13:26:50 ['asd','qwe','qwe'] 100500
2015-01-01 7 39 2014-07-14 13:26:50 ['120','130','140'] 0
2015-01-01 8 40 2012-12-12 12:12:12 ['12','13','14'] 0
2015-01-01 9 41 1992-01-01 08:00:00 [] 0
2015-01-01 10 42 0000-00-00 00:00:00 [] 0
d Date
k UInt64
i32 Int32
dt DateTime
s UInt32
CREATE TABLE test.alter ( d Date, k UInt64, i32 Int32, dt DateTime, s UInt32) ENGINE = MergeTree(d, k, 8192)
2015-01-01 6 38 2014-07-15 13:26:50 100500
2015-01-01 7 39 2014-07-14 13:26:50 0
2015-01-01 8 40 2012-12-12 12:12:12 0
2015-01-01 9 41 1992-01-01 08:00:00 0
2015-01-01 10 42 0000-00-00 00:00:00 0
d Date
k UInt64
i32 Int32
dt DateTime
s UInt32
n.s Array(String)
n.d Array(Date)
CREATE TABLE test.alter ( d Date, k UInt64, i32 Int32, dt DateTime, s UInt32, `n.s` Array(String), `n.d` Array(Date)) ENGINE = MergeTree(d, k, 8192)
2015-01-01 6 38 2014-07-15 13:26:50 100500 [] []
2015-01-01 7 39 2014-07-14 13:26:50 0 [] []
2015-01-01 8 40 2012-12-12 12:12:12 0 [] []
2015-01-01 9 41 1992-01-01 08:00:00 0 [] []
2015-01-01 10 42 0000-00-00 00:00:00 0 [] []
d Date
k UInt64
i32 Int32
dt DateTime
s UInt32
CREATE TABLE test.alter ( d Date, k UInt64, i32 Int32, dt DateTime, s UInt32) ENGINE = MergeTree(d, k, 8192)
2015-01-01 6 38 2014-07-15 13:26:50 100500
2015-01-01 7 39 2014-07-14 13:26:50 0
2015-01-01 8 40 2012-12-12 12:12:12 0
2015-01-01 9 41 1992-01-01 08:00:00 0
2015-01-01 10 42 0000-00-00 00:00:00 0
d Date
k UInt64
i32 Int32
dt String
s String
CREATE TABLE test.alter ( d Date, k UInt64, i32 Int32, dt String, s String) ENGINE = MergeTree(d, k, 8192)
2015-01-01 6 38 2014-07-15 13:26:50 100500
2015-01-01 7 39 2014-07-14 13:26:50 0
2015-01-01 8 40 2012-12-12 12:12:12 0
2015-01-01 9 41 1992-01-01 08:00:00 0
2015-01-01 10 42 0000-00-00 00:00:00 0

View File

@ -5,80 +5,80 @@ INSERT INTO test.alter VALUES ('2015-01-01', 10, 42);
DESC TABLE test.alter;
SHOW CREATE TABLE test.alter;
SELECT * FROM test.alter;
SELECT * FROM test.alter ORDER BY k;
ALTER TABLE test.alter ADD COLUMN dt DateTime;
INSERT INTO test.alter VALUES ('2015-01-01', 9, 41, '1992-01-01 08:00:00');
DESC TABLE test.alter;
SHOW CREATE TABLE test.alter;
SELECT * FROM test.alter;
SELECT * FROM test.alter ORDER BY k;
ALTER TABLE test.alter ADD COLUMN n Nested(ui8 UInt8, s String);
INSERT INTO test.alter VALUES ('2015-01-01', 8, 40, '2012-12-12 12:12:12', [1,2,3], ['12','13','14']);
DESC TABLE test.alter;
SHOW CREATE TABLE test.alter;
SELECT * FROM test.alter;
SELECT * FROM test.alter ORDER BY k;
ALTER TABLE test.alter ADD COLUMN `n.d` Array(Date);
INSERT INTO test.alter VALUES ('2015-01-01', 7, 39, '2014-07-14 13:26:50', [10,20,30], ['120','130','140'],['2000-01-01','2000-01-01','2000-01-03']);
DESC TABLE test.alter;
SHOW CREATE TABLE test.alter;
SELECT * FROM test.alter;
SELECT * FROM test.alter ORDER BY k;
ALTER TABLE test.alter ADD COLUMN s String;
INSERT INTO test.alter VALUES ('2015-01-01', 6,38,'2014-07-15 13:26:50',[10,20,30],['asd','qwe','qwe'],['2000-01-01','2000-01-01','2000-01-03'],'100500');
DESC TABLE test.alter;
SHOW CREATE TABLE test.alter;
SELECT * FROM test.alter;
SELECT * FROM test.alter ORDER BY k;
ALTER TABLE test.alter DROP COLUMN `n.d`, MODIFY COLUMN s Int64;
DESC TABLE test.alter;
SHOW CREATE TABLE test.alter;
SELECT * FROM test.alter;
SELECT * FROM test.alter ORDER BY k;
ALTER TABLE test.alter ADD COLUMN `n.d` Array(Date), MODIFY COLUMN s UInt32;
DESC TABLE test.alter;
SHOW CREATE TABLE test.alter;
SELECT * FROM test.alter;
SELECT * FROM test.alter ORDER BY k;
OPTIMIZE TABLE test.alter;
SELECT * FROM test.alter;
SELECT * FROM test.alter ORDER BY k;
ALTER TABLE test.alter DROP COLUMN n.ui8, DROP COLUMN n.d;
DESC TABLE test.alter;
SHOW CREATE TABLE test.alter;
SELECT * FROM test.alter;
SELECT * FROM test.alter ORDER BY k;
ALTER TABLE test.alter DROP COLUMN n.s;
DESC TABLE test.alter;
SHOW CREATE TABLE test.alter;
SELECT * FROM test.alter;
SELECT * FROM test.alter ORDER BY k;
ALTER TABLE test.alter ADD COLUMN n.s Array(String), ADD COLUMN n.d Array(Date);
DESC TABLE test.alter;
SHOW CREATE TABLE test.alter;
SELECT * FROM test.alter;
SELECT * FROM test.alter ORDER BY k;
ALTER TABLE test.alter DROP COLUMN n;
DESC TABLE test.alter;
SHOW CREATE TABLE test.alter;
SELECT * FROM test.alter;
SELECT * FROM test.alter ORDER BY k;
ALTER TABLE test.alter MODIFY COLUMN dt String, MODIFY COLUMN s String;
DESC TABLE test.alter;
SHOW CREATE TABLE test.alter;
SELECT * FROM test.alter;
SELECT * FROM test.alter ORDER BY k;
DROP TABLE test.alter;