Fix rename with compact parts

This commit is contained in:
alesapin 2020-05-14 19:56:13 +03:00
parent 316773d853
commit 8eb27f6f13
3 changed files with 45 additions and 5 deletions

View File

@ -187,17 +187,17 @@ void IMergeTreeReader::evaluateMissingDefaults(Block additional_columns, Columns
NameAndTypePair IMergeTreeReader::getColumnFromPart(const NameAndTypePair & required_column) const
{
auto it = columns_from_part.find(required_column.name);
if (it != columns_from_part.end())
return {it->first, it->second};
if (alter_conversions.isColumnRenamed(required_column.name))
{
String old_name = alter_conversions.getColumnOldName(required_column.name);
it = columns_from_part.find(old_name);
auto it = columns_from_part.find(old_name);
if (it != columns_from_part.end())
return {it->first, it->second};
}
else if (auto it = columns_from_part.find(required_column.name); it != columns_from_part.end())
{
return {it->first, it->second};
}
return required_column;
}

View File

@ -1,3 +1,11 @@
CREATE TABLE default.rename_table\n(\n `key` Int32, \n `old_value1` Int32, \n `value1` Int32\n)\nENGINE = MergeTree\nORDER BY tuple()\nSETTINGS index_granularity = 8192
key old_value1 value1
1 2 3
CREATE TABLE default.rename_table\n(\n `k` Int32, \n `v1` Int32, \n `v2` Int32\n)\nENGINE = MergeTree\nORDER BY tuple()\nSETTINGS index_granularity = 8192
k v1 v2
1 2 3
4 5 6
---polymorphic---
CREATE TABLE default.rename_table_polymorphic\n(\n `key` Int32, \n `old_value1` Int32, \n `value1` Int32\n)\nENGINE = MergeTree\nORDER BY tuple()\nSETTINGS min_rows_for_wide_part = 10000, index_granularity = 8192
key old_value1 value1
1 2 3

View File

@ -11,4 +11,36 @@ SHOW CREATE TABLE rename_table;
SELECT * FROM rename_table FORMAT TSVWithNames;
INSERT INTO rename_table VALUES (4, 5, 6);
-- rename all columns simultaneously
ALTER TABLE rename_table RENAME COLUMN old_value1 TO v1, RENAME COLUMN value1 TO v2, RENAME COLUMN key to k;
SHOW CREATE TABLE rename_table;
SELECT * FROM rename_table ORDER BY k FORMAT TSVWithNames;
DROP TABLE IF EXISTS rename_table;
SELECT '---polymorphic---';
DROP TABLE IF EXISTS rename_table_polymorphic;
CREATE TABLE rename_table_polymorphic (
key Int32,
value1 Int32,
value2 Int32
)
ENGINE = MergeTree
ORDER BY tuple()
SETTINGS min_rows_for_wide_part = 10000;
INSERT INTO rename_table_polymorphic VALUES (1, 2, 3);
ALTER TABLE rename_table_polymorphic RENAME COLUMN value1 TO old_value1, RENAME COLUMN value2 TO value1;
SHOW CREATE TABLE rename_table_polymorphic;
SELECT * FROM rename_table_polymorphic FORMAT TSVWithNames;
DROP TABLE IF EXISTS rename_table_polymorphic;