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