2018-09-12 05:41:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-25 11:43:19 +00:00
|
|
|
#include <Interpreters/Aliases.h>
|
2018-12-06 19:02:42 +00:00
|
|
|
#include <Interpreters/InDepthNodeVisitor.h>
|
2018-09-12 05:41:09 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-07-22 19:21:07 +00:00
|
|
|
class ASTSelectQuery;
|
2018-11-02 15:09:15 +00:00
|
|
|
class ASTSubquery;
|
|
|
|
struct ASTTableExpression;
|
|
|
|
struct ASTArrayJoin;
|
|
|
|
|
2018-12-06 19:02:42 +00:00
|
|
|
/// Visits AST node to collect aliases.
|
|
|
|
class QueryAliasesMatcher
|
2018-09-27 19:25:18 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-03-08 11:07:05 +00:00
|
|
|
using Visitor = ConstInDepthNodeVisitor<QueryAliasesMatcher, false>;
|
2019-02-22 13:33:56 +00:00
|
|
|
|
2018-12-06 19:02:42 +00:00
|
|
|
struct Data
|
|
|
|
{
|
|
|
|
Aliases & aliases;
|
|
|
|
};
|
2018-09-27 19:25:18 +00:00
|
|
|
|
2020-03-08 11:07:05 +00:00
|
|
|
static void visit(const ASTPtr & ast, Data & data);
|
|
|
|
static bool needChildVisit(const ASTPtr & node, const ASTPtr & child);
|
2018-11-02 15:09:15 +00:00
|
|
|
|
2018-12-06 19:02:42 +00:00
|
|
|
private:
|
2019-07-22 19:21:07 +00:00
|
|
|
static void visit(const ASTSelectQuery & select, const ASTPtr & ast, Data & data);
|
2020-03-08 11:07:05 +00:00
|
|
|
static void visit(const ASTSubquery & subquery, const ASTPtr & ast, Data & data);
|
2019-02-22 13:33:56 +00:00
|
|
|
static void visit(const ASTArrayJoin &, const ASTPtr & ast, Data & data);
|
2018-12-06 19:02:42 +00:00
|
|
|
static void visitOther(const ASTPtr & ast, Data & data);
|
2018-09-27 19:25:18 +00:00
|
|
|
};
|
2018-09-12 05:41:09 +00:00
|
|
|
|
2018-12-06 19:02:42 +00:00
|
|
|
/// Visits AST nodes and collect their aliases in one map (with links to source nodes).
|
2019-02-22 13:33:56 +00:00
|
|
|
using QueryAliasesVisitor = QueryAliasesMatcher::Visitor;
|
2018-12-06 19:02:42 +00:00
|
|
|
|
2018-09-12 05:41:09 +00:00
|
|
|
}
|