Fix ALTER column with column names with dots

This commit is contained in:
avogar 2022-06-10 08:58:00 +00:00
parent 349f1b140a
commit a4f378f8c3
3 changed files with 47 additions and 7 deletions

View File

@ -173,16 +173,14 @@ static auto getNameRange(const ColumnsDescription::ColumnsContainer & columns, c
{
String name_with_dot = name_without_dot + ".";
auto begin = columns.begin();
for (; begin != columns.end(); ++begin)
for (auto it = columns.begin(); it != columns.end(); ++it)
{
if (begin->name == name_without_dot)
return std::make_pair(begin, std::next(begin));
if (startsWith(begin->name, name_with_dot))
break;
if (it->name == name_without_dot)
return std::make_pair(it, std::next(it));
}
auto begin = std::find_if(columns.begin(), columns.end(), [&](const auto & column){ return startsWith(column.name, name_with_dot); });
if (begin == columns.end())
return std::make_pair(begin, begin);

View File

@ -0,0 +1,27 @@
id String
abc.1 String
abc.2 String
abc String
id String
abc.2 String
abc String
abc.1 String
id String
abc String
abc.2 String
abc.1 String
id String
abc.2 String
abc String
abc.1 String
id String
abc String
abc.2 String
abc.1 String
id String
abc.2 String
abc.1 String
abc String
id String
abc.2 String
abc.1 String

View File

@ -0,0 +1,15 @@
DROP TABLE IF EXISTS test;
CREATE TABLE test (id String, `abc.1` String, `abc.2` String, `abc` String) ENGINE MergeTree order by id;
DESC TABLE test;
ALTER TABLE test MODIFY COLUMN `abc.1` String AFTER `abc`;
DESC TABLE test;
ALTER TABLE test MODIFY COLUMN `abc.2` String AFTER `abc`;
DESC TABLE test;
ALTER TABLE test MODIFY COLUMN `abc` String AFTER `abc.2`;
DESC TABLE test;
ALTER TABLE test MODIFY COLUMN `abc` String AFTER `id`;
DESC TABLE test;
ALTER TABLE test MODIFY COLUMN `abc` String AFTER `abc.1`;
DESC TABLE test;
ALTER TABLE test DROP COLUMN `abc`;
DESC TABLE test;