mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 01:22:04 +00:00
mJOIN: correct names for left table columns
This commit is contained in:
parent
b2fa415858
commit
10b473bb24
@ -35,19 +35,21 @@ struct ColumnAliasesMatcher
|
||||
struct Data
|
||||
{
|
||||
const std::vector<DatabaseAndTableWithAlias> tables;
|
||||
bool public_names;
|
||||
AsteriskSemantic::RevertedAliases rev_aliases;
|
||||
std::unordered_map<String, String> aliases;
|
||||
std::vector<ASTIdentifier *> compound_identifiers;
|
||||
std::vector<std::pair<ASTIdentifier *, bool>> compound_identifiers;
|
||||
|
||||
Data(std::vector<DatabaseAndTableWithAlias> && tables_)
|
||||
: tables(tables_)
|
||||
, public_names(false)
|
||||
{}
|
||||
|
||||
void replaceIdentifiersWithAliases()
|
||||
{
|
||||
String hide_prefix = "--"; /// @note restriction: user should not use alises like `--table.column`
|
||||
|
||||
for (auto * identifier : compound_identifiers)
|
||||
for (auto & [identifier, is_public] : compound_identifiers)
|
||||
{
|
||||
auto it = rev_aliases.find(identifier->name);
|
||||
if (it == rev_aliases.end())
|
||||
@ -61,7 +63,8 @@ struct ColumnAliasesMatcher
|
||||
rev_aliases[long_name].push_back(alias);
|
||||
|
||||
identifier->setShortName(alias);
|
||||
//identifier->setAlias(long_name);
|
||||
if (is_public)
|
||||
identifier->setAlias(long_name);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -130,7 +133,7 @@ struct ColumnAliasesMatcher
|
||||
}
|
||||
}
|
||||
else
|
||||
data.compound_identifiers.push_back(&node);
|
||||
data.compound_identifiers.emplace_back(&node, data.public_names);
|
||||
}
|
||||
};
|
||||
|
||||
@ -236,7 +239,11 @@ void JoinToSubqueryTransformMatcher::visit(ASTSelectQuery & select, ASTPtr &, Da
|
||||
|
||||
ColumnAliasesVisitor::Data aliases_data(getDatabaseAndTables(select, ""));
|
||||
if (select.select_expression_list)
|
||||
{
|
||||
aliases_data.public_names = true;
|
||||
ColumnAliasesVisitor(aliases_data).visit(select.select_expression_list);
|
||||
aliases_data.public_names = false;
|
||||
}
|
||||
if (select.where_expression)
|
||||
ColumnAliasesVisitor(aliases_data).visit(select.where_expression);
|
||||
if (select.prewhere_expression)
|
||||
|
@ -5,9 +5,9 @@
|
||||
0 0 0
|
||||
10 100 1000
|
||||
20 200 2000
|
||||
┌─--t1.a─┬─--t2.a─┬─--t2.b─┬─--t3.b─┬─--t3.c─┬─a─┬─b─┬─c─┐
|
||||
│ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │
|
||||
└────────┴────────┴────────┴────────┴────────┴───┴───┴───┘
|
||||
┌─t1.a─┬─t2.a─┬─t2.b─┬─t3.b─┬─t3.c─┬─a─┬─b─┬─c─┐
|
||||
│ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │
|
||||
└──────┴──────┴──────┴──────┴──────┴───┴───┴───┘
|
||||
0 0 0 0
|
||||
6 6 60 60
|
||||
12 12 120 120
|
||||
|
Loading…
Reference in New Issue
Block a user