2018-09-28 15:01:13 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-09-27 19:25:18 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2019-01-16 17:26:14 +00:00
|
|
|
#include <Core/Names.h>
|
2018-10-30 16:31:21 +00:00
|
|
|
#include <Interpreters/DatabaseAndTableWithAlias.h>
|
2018-12-06 15:29:55 +00:00
|
|
|
#include <Interpreters/InDepthNodeVisitor.h>
|
2018-09-27 19:25:18 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-12-06 15:29:55 +00:00
|
|
|
class ASTIdentifier;
|
|
|
|
class ASTQualifiedAsterisk;
|
|
|
|
struct ASTTableJoin;
|
|
|
|
class ASTSelectQuery;
|
2018-09-27 19:25:18 +00:00
|
|
|
|
2018-12-06 15:29:55 +00:00
|
|
|
/// Visit one node for names qualification. @sa InDepthNodeVisitor.
|
|
|
|
class TranslateQualifiedNamesMatcher
|
2018-09-27 19:25:18 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-12-06 15:29:55 +00:00
|
|
|
struct Data
|
2018-09-27 19:25:18 +00:00
|
|
|
{
|
2018-12-06 15:29:55 +00:00
|
|
|
const NameSet & source_columns;
|
|
|
|
const std::vector<DatabaseAndTableWithAlias> & tables;
|
|
|
|
};
|
2018-09-27 19:25:18 +00:00
|
|
|
|
2018-12-07 12:34:40 +00:00
|
|
|
static constexpr const char * label = "TranslateQualifiedNames";
|
2018-09-27 19:25:18 +00:00
|
|
|
|
2018-12-07 14:24:47 +00:00
|
|
|
static std::vector<ASTPtr *> visit(ASTPtr & ast, Data & data);
|
2018-12-06 15:29:55 +00:00
|
|
|
static bool needChildVisit(ASTPtr & node, const ASTPtr & child);
|
2018-09-27 19:25:18 +00:00
|
|
|
|
2018-12-06 15:29:55 +00:00
|
|
|
private:
|
2018-12-07 14:24:47 +00:00
|
|
|
static std::vector<ASTPtr *> visit(const ASTIdentifier & node, ASTPtr & ast, Data &);
|
|
|
|
static std::vector<ASTPtr *> visit(const ASTQualifiedAsterisk & node, const ASTPtr & ast, Data &);
|
|
|
|
static std::vector<ASTPtr *> visit(ASTTableJoin & node, const ASTPtr & ast, Data &);
|
|
|
|
static std::vector<ASTPtr *> visit(ASTSelectQuery & node, const ASTPtr & ast, Data &);
|
2018-09-27 19:25:18 +00:00
|
|
|
};
|
|
|
|
|
2018-12-06 15:29:55 +00:00
|
|
|
/// Visits AST for names qualification.
|
|
|
|
/// It finds columns (general identifiers and asterisks) and translate their names according to tables' names.
|
|
|
|
using TranslateQualifiedNamesVisitor = InDepthNodeVisitor<TranslateQualifiedNamesMatcher, true>;
|
|
|
|
|
2018-09-27 19:25:18 +00:00
|
|
|
}
|