mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-18 21:51:57 +00:00
5678d1ed98
* StorageSystemContributors clean * Fix * ARM fixes * Fix arm compile * fix * Fix macos? * Fix includes * fix * fix * Try fix apple build part 1 * Fix identation * Fix static libc++ in clang * fix arm build * better * fix * fix * better check-include
53 lines
1.2 KiB
C++
53 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <Interpreters/Context.h>
|
|
#include <Parsers/IAST.h>
|
|
#include <Parsers/ASTIdentifier.h>
|
|
#include <Common/typeid_cast.h>
|
|
|
|
namespace DB
|
|
{
|
|
|
|
/// Finds in the query the usage of external tables (as table identifiers). Fills in external_tables.
|
|
class ExternalTablesVisitor
|
|
{
|
|
public:
|
|
ExternalTablesVisitor(const Context & context_, Tables & tables)
|
|
: context(context_),
|
|
external_tables(tables)
|
|
{}
|
|
|
|
void visit(ASTPtr & ast) const
|
|
{
|
|
/// Traverse from the bottom. Intentionally go into subqueries.
|
|
for (auto & child : ast->children)
|
|
visit(child);
|
|
|
|
tryVisit<ASTIdentifier>(ast);
|
|
}
|
|
|
|
private:
|
|
const Context & context;
|
|
Tables & external_tables;
|
|
|
|
void visit(const ASTIdentifier & node, ASTPtr &) const
|
|
{
|
|
if (node.special())
|
|
if (StoragePtr external_storage = context.tryGetExternalTable(node.name))
|
|
external_tables[node.name] = external_storage;
|
|
}
|
|
|
|
template <typename T>
|
|
bool tryVisit(ASTPtr & ast) const
|
|
{
|
|
if (const T * t = typeid_cast<const T *>(ast.get()))
|
|
{
|
|
visit(*t, ast);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
};
|
|
|
|
}
|