1 | #include <Interpreters/FindIdentifierBestTableVisitor.h> |
---|---|
2 | #include <Interpreters/IdentifierSemantic.h> |
3 | |
4 | |
5 | namespace DB |
6 | { |
7 | |
8 | FindIdentifierBestTableData::FindIdentifierBestTableData(const std::vector<TableWithColumnNames> & tables_) |
9 | : tables(tables_) |
10 | { |
11 | } |
12 | |
13 | void FindIdentifierBestTableData::visit(ASTIdentifier & identifier, ASTPtr &) |
14 | { |
15 | const DatabaseAndTableWithAlias * best_table = nullptr; |
16 | |
17 | if (!identifier.compound()) |
18 | { |
19 | for (const auto & table_names : tables) |
20 | { |
21 | auto & columns = table_names.columns; |
22 | if (std::find(columns.begin(), columns.end(), identifier.name) != columns.end()) |
23 | { |
24 | // TODO: make sure no collision ever happens |
25 | if (!best_table) |
26 | best_table = &table_names.table; |
27 | } |
28 | } |
29 | } |
30 | else |
31 | { |
32 | size_t best_table_pos = 0; |
33 | if (IdentifierSemantic::chooseTable(identifier, tables, best_table_pos)) |
34 | best_table = &tables[best_table_pos].table; |
35 | } |
36 | |
37 | identifier_table.emplace_back(&identifier, best_table); |
38 | } |
39 | |
40 | } |
41 |