mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
better column to table matching: check if table has qualified column
This commit is contained in:
parent
30acb1b653
commit
d70904d7ee
@ -66,6 +66,13 @@ void TranslateQualifiedNamesMatcher::visit(ASTIdentifier & identifier, ASTPtr &,
|
||||
bool allow_ambiguous = data.join_using_columns.count(short_name);
|
||||
if (IdentifierSemantic::chooseTable(identifier, data.tables, table_pos, allow_ambiguous))
|
||||
{
|
||||
if (data.unknownColumn(table_pos, short_name))
|
||||
{
|
||||
String table_name = data.tables[table_pos].first.getQualifiedNamePrefix(false);
|
||||
throw Exception("There's no column '" + identifier.name + "' in table '" + table_name + "'",
|
||||
ErrorCodes::UNKNOWN_IDENTIFIER);
|
||||
}
|
||||
|
||||
IdentifierSemantic::setMembership(identifier, table_pos);
|
||||
|
||||
/// In case if column from the joined table are in source columns, change it's name to qualified.
|
||||
|
@ -39,6 +39,15 @@ public:
|
||||
bool hasTable() const { return !tables.empty(); }
|
||||
bool processAsterisks() const { return hasTable() && has_columns; }
|
||||
|
||||
bool unknownColumn(size_t table_pos, const String & name) const
|
||||
{
|
||||
const Names & names = tables[table_pos].second;
|
||||
for (auto & known_name : names)
|
||||
if (name == known_name)
|
||||
return false;
|
||||
return !names.empty();
|
||||
}
|
||||
|
||||
static std::vector<TableWithColumnNames> tablesOnly(const std::vector<DatabaseAndTableWithAlias> & tables)
|
||||
{
|
||||
std::vector<TableWithColumnNames> tables_with_columns;
|
||||
|
@ -1,7 +1,7 @@
|
||||
SELECT
|
||||
q0.dt,
|
||||
q0.cnt,
|
||||
q0.cnt2
|
||||
q1.cnt2
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
|
@ -0,0 +1 @@
|
||||
1 3
|
@ -0,0 +1,3 @@
|
||||
SELECT l.c FROM (SELECT 1 AS a, 2 AS b) AS l join (SELECT 2 AS b, 3 AS c) AS r USING b; -- { serverError 47 }
|
||||
SELECT r.a FROM (SELECT 1 AS a, 2 AS b) AS l join (SELECT 2 AS b, 3 AS c) AS r USING b; -- { serverError 47 }
|
||||
SELECT l.a, r.c FROM (SELECT 1 AS a, 2 AS b) AS l join (SELECT 2 AS b, 3 AS c) AS r USING b;
|
Loading…
Reference in New Issue
Block a user