mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-19 06:01:57 +00:00
40 lines
962 B
C++
40 lines
962 B
C++
|
#include <Interpreters/FindIdentifierBestTableVisitor.h>
|
||
|
#include <Interpreters/IdentifierSemantic.h>
|
||
|
|
||
|
|
||
|
namespace DB
|
||
|
{
|
||
|
|
||
|
FindIdentifierBestTableData::FindIdentifierBestTableData(const std::vector<DatabaseAndTableWithAlias> & tables_)
|
||
|
: tables(tables_)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void FindIdentifierBestTableData::visit(ASTIdentifier & identifier, ASTPtr &)
|
||
|
{
|
||
|
const DatabaseAndTableWithAlias * best_table = nullptr;
|
||
|
|
||
|
if (!identifier.compound())
|
||
|
{
|
||
|
if (!tables.empty())
|
||
|
best_table = &tables[0];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
size_t best_match = 0;
|
||
|
for (const DatabaseAndTableWithAlias & table : tables)
|
||
|
{
|
||
|
if (size_t match = IdentifierSemantic::canReferColumnToTable(identifier, table))
|
||
|
if (match > best_match)
|
||
|
{
|
||
|
best_match = match;
|
||
|
best_table = &table;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
identifier_table.emplace_back(&identifier, best_table);
|
||
|
}
|
||
|
|
||
|
}
|