1#pragma once
2
3#include <Interpreters/Aliases.h>
4#include <Interpreters/InDepthNodeVisitor.h>
5
6namespace DB
7{
8
9class ASTSelectQuery;
10class ASTSubquery;
11struct ASTTableExpression;
12struct ASTArrayJoin;
13
14/// Visits AST node to collect aliases.
15class QueryAliasesMatcher
16{
17public:
18 using Visitor = InDepthNodeVisitor<QueryAliasesMatcher, false>;
19
20 struct Data
21 {
22 Aliases & aliases;
23 };
24
25 static void visit(ASTPtr & ast, Data & data);
26 static bool needChildVisit(ASTPtr & node, const ASTPtr & child);
27
28private:
29 static void visit(const ASTSelectQuery & select, const ASTPtr & ast, Data & data);
30 static void visit(ASTSubquery & subquery, const ASTPtr & ast, Data & data);
31 static void visit(const ASTArrayJoin &, const ASTPtr & ast, Data & data);
32 static void visitOther(const ASTPtr & ast, Data & data);
33};
34
35/// Visits AST nodes and collect their aliases in one map (with links to source nodes).
36using QueryAliasesVisitor = QueryAliasesMatcher::Visitor;
37
38}
39