1 | #pragma once |
2 | |
3 | #include <map> |
4 | |
5 | #include <Parsers/IAST.h> |
6 | #include <Interpreters/Aliases.h> |
7 | |
8 | namespace DB |
9 | { |
10 | |
11 | class ASTSelectQuery; |
12 | class ASTIdentifier; |
13 | struct ASTTablesInSelectQueryElement; |
14 | class Context; |
15 | |
16 | |
17 | class QueryNormalizer |
18 | { |
19 | /// Extracts settings, mostly to show which are used and which are not. |
20 | struct |
21 | { |
22 | const UInt64 ; |
23 | const UInt64 max_expanded_ast_elements; |
24 | |
25 | template <typename T> |
26 | (const T & settings) |
27 | : max_ast_depth(settings.max_ast_depth), |
28 | max_expanded_ast_elements(settings.max_expanded_ast_elements) |
29 | {} |
30 | }; |
31 | |
32 | public: |
33 | struct Data |
34 | { |
35 | using SetOfASTs = std::set<const IAST *>; |
36 | using MapOfASTs = std::map<ASTPtr, ASTPtr>; |
37 | |
38 | const Aliases & aliases; |
39 | const ExtractedSettings settings; |
40 | |
41 | /// tmp data |
42 | size_t level; |
43 | MapOfASTs finished_asts; /// already processed vertices (and by what they replaced) |
44 | SetOfASTs current_asts; /// vertices in the current call stack of this method |
45 | std::string current_alias; /// the alias referencing to the ancestor of ast (the deepest ancestor with aliases) |
46 | |
47 | Data(const Aliases & aliases_, ExtractedSettings && settings_) |
48 | : aliases(aliases_) |
49 | , settings(settings_) |
50 | , level(0) |
51 | {} |
52 | }; |
53 | |
54 | QueryNormalizer(Data & data) |
55 | : visitor_data(data) |
56 | {} |
57 | |
58 | void visit(ASTPtr & ast) |
59 | { |
60 | visit(ast, visitor_data); |
61 | } |
62 | |
63 | private: |
64 | Data & visitor_data; |
65 | |
66 | static void visit(ASTPtr & query, Data & data); |
67 | |
68 | static void visit(ASTIdentifier &, ASTPtr &, Data &); |
69 | static void visit(ASTTablesInSelectQueryElement &, const ASTPtr &, Data &); |
70 | static void visit(ASTSelectQuery &, const ASTPtr &, Data &); |
71 | |
72 | static void visitChildren(const ASTPtr &, Data & data); |
73 | }; |
74 | |
75 | } |
76 | |