2018-10-16 19:00:05 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-11-10 20:09:07 +00:00
|
|
|
#include <Interpreters/Context.h>
|
|
|
|
#include <Parsers/IAST.h>
|
|
|
|
#include <Parsers/ASTIdentifier.h>
|
|
|
|
#include <Common/typeid_cast.h>
|
2018-12-07 15:14:50 +00:00
|
|
|
#include <Interpreters/InDepthNodeVisitor.h>
|
2019-01-25 15:42:24 +00:00
|
|
|
#include <Interpreters/IdentifierSemantic.h>
|
2018-11-10 20:09:07 +00:00
|
|
|
|
2018-10-16 19:00:05 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-12-07 15:14:50 +00:00
|
|
|
/// If node is ASTIdentifier try to extract external_storage.
|
|
|
|
class ExternalTablesMatcher
|
2018-10-16 19:00:05 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-12-07 15:14:50 +00:00
|
|
|
struct Data
|
2018-10-16 19:00:05 +00:00
|
|
|
{
|
2018-12-07 15:14:50 +00:00
|
|
|
const Context & context;
|
|
|
|
Tables & external_tables;
|
|
|
|
};
|
2018-10-16 19:00:05 +00:00
|
|
|
|
2019-02-22 13:33:56 +00:00
|
|
|
static void visit(ASTPtr & ast, Data & data)
|
2018-10-16 19:00:05 +00:00
|
|
|
{
|
2019-03-11 13:22:51 +00:00
|
|
|
if (const auto * t = ast->as<ASTIdentifier>())
|
2019-02-22 13:33:56 +00:00
|
|
|
visit(*t, ast, data);
|
2018-10-16 19:00:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-07 15:14:50 +00:00
|
|
|
static bool needChildVisit(ASTPtr &, const ASTPtr &) { return true; }
|
|
|
|
|
|
|
|
private:
|
2019-02-22 13:33:56 +00:00
|
|
|
static void visit(const ASTIdentifier & node, ASTPtr &, Data & data)
|
2018-10-16 19:00:05 +00:00
|
|
|
{
|
2019-01-25 15:42:24 +00:00
|
|
|
if (auto opt_name = IdentifierSemantic::getTableName(node))
|
2019-01-14 18:15:04 +00:00
|
|
|
if (StoragePtr external_storage = data.context.tryGetExternalTable(*opt_name))
|
|
|
|
data.external_tables[*opt_name] = external_storage;
|
2018-10-16 19:00:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-07 15:14:50 +00:00
|
|
|
/// Finds in the query the usage of external tables. Fills in external_tables.
|
|
|
|
using ExternalTablesVisitor = InDepthNodeVisitor<ExternalTablesMatcher, false>;
|
|
|
|
|
2018-10-16 19:00:05 +00:00
|
|
|
}
|