mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
dbms: Server: modify columns renaming rules [#METR-14099]
This commit is contained in:
parent
9c9db14d95
commit
255c7669a9
@ -52,7 +52,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Переименовать столбцы в такие же имена, как в source.
|
||||
/// Переименовать столбцы запроса в такие же имена, как в исходном запросе.
|
||||
void renameColumns(const ASTSelectQuery & source)
|
||||
{
|
||||
const ASTs & from = source.select_expression_list->children;
|
||||
@ -64,14 +64,15 @@ public:
|
||||
|
||||
for (size_t i = 0; i < from.size(); ++i)
|
||||
{
|
||||
const auto & from_alias = from[i]->tryGetAlias();
|
||||
const auto & to_alias = to[i]->tryGetAlias();
|
||||
if (!to_alias.empty() && !from_alias.empty())
|
||||
if (to_alias != from_alias)
|
||||
throw Exception("Column alias mismatch in UNION ALL chain",
|
||||
/// Если столбец имеет алиас, то он должен совпадать с названием исходного столбца.
|
||||
/// В противном случае мы ему присваиваем алиас, если требуется.
|
||||
if (!to[i]->tryGetAlias().empty())
|
||||
{
|
||||
if (to[i]->tryGetAlias() != from[i]->getAliasOrColumnName())
|
||||
throw Exception("Column alias mismatch in UNION ALL chain",
|
||||
DB::ErrorCodes::UNION_ALL_COLUMN_ALIAS_MISMATCH);
|
||||
|
||||
if (to[i]->getAliasOrColumnName() != from[i]->getAliasOrColumnName())
|
||||
}
|
||||
else if (to[i]->getColumnName() != from[i]->getAliasOrColumnName())
|
||||
to[i]->setAlias(from[i]->getAliasOrColumnName());
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
DROP TABLE IF EXISTS data2013;
|
||||
DROP TABLE IF EXISTS data2014;
|
||||
DROP TABLE IF EXISTS data2015;
|
||||
|
||||
CREATE TABLE data2013 (name String, value UInt32) ENGINE = Memory;
|
||||
CREATE TABLE data2014 (name String, value UInt32) ENGINE = Memory;
|
||||
CREATE TABLE data2015 (data_name String, data_value UInt32) ENGINE = Memory;
|
||||
|
||||
INSERT INTO data2013(name,value) VALUES('Alice', 1000);
|
||||
INSERT INTO data2013(name,value) VALUES('Bob', 2000);
|
||||
@ -12,6 +14,9 @@ INSERT INTO data2014(name,value) VALUES('Alice', 2000);
|
||||
INSERT INTO data2014(name,value) VALUES('Bob', 2000);
|
||||
INSERT INTO data2014(name,value) VALUES('Dennis', 35000);
|
||||
|
||||
INSERT INTO data2015(data_name, data_value) VALUES('Foo', 42);
|
||||
INSERT INTO data2015(data_name, data_value) VALUES('Bar', 1);
|
||||
|
||||
SELECT val FROM
|
||||
(SELECT value AS val FROM data2013 WHERE name = 'Alice'
|
||||
UNION ALL
|
||||
|
@ -1 +1 @@
|
||||
SELECT * FROM (SELECT 1 UNION ALL SELECT 2 AS X) ORDER BY 1 ASC;
|
||||
SELECT * FROM (SELECT 1 UNION ALL SELECT 2) ORDER BY 1 ASC;
|
||||
|
@ -1 +1 @@
|
||||
SELECT * FROM (SELECT 1 UNION ALL SELECT 2 AS X UNION ALL SELECT 3 AS Y) ORDER BY 1 ASC;
|
||||
SELECT * FROM (SELECT 1 AS X UNION ALL SELECT 2 UNION ALL SELECT 3 AS X) ORDER BY X ASC;
|
||||
|
@ -0,0 +1,5 @@
|
||||
Alice
|
||||
Bar
|
||||
Bob
|
||||
Carol
|
||||
Foo
|
1
dbms/tests/queries/0_stateless/00098_d_union_all.sql
Normal file
1
dbms/tests/queries/0_stateless/00098_d_union_all.sql
Normal file
@ -0,0 +1 @@
|
||||
SELECT name FROM (SELECT name FROM data2013 UNION ALL SELECT data_name FROM data2015) ORDER BY name ASC;
|
@ -0,0 +1,5 @@
|
||||
Alice
|
||||
Bar
|
||||
Bob
|
||||
Carol
|
||||
Foo
|
1
dbms/tests/queries/0_stateless/00098_e_union_all.sql
Normal file
1
dbms/tests/queries/0_stateless/00098_e_union_all.sql
Normal file
@ -0,0 +1 @@
|
||||
SELECT X FROM (SELECT name AS X FROM data2013 UNION ALL SELECT data_name FROM data2015) ORDER BY X ASC;
|
@ -0,0 +1,5 @@
|
||||
Alice
|
||||
Bar
|
||||
Bob
|
||||
Carol
|
||||
Foo
|
1
dbms/tests/queries/0_stateless/00098_f_union_all.sql
Normal file
1
dbms/tests/queries/0_stateless/00098_f_union_all.sql
Normal file
@ -0,0 +1 @@
|
||||
SELECT name FROM (SELECT name FROM data2013 UNION ALL SELECT data_name AS name FROM data2015) ORDER BY name ASC;
|
Loading…
Reference in New Issue
Block a user