| 1 | #pragma once | 
|---|
| 2 |  | 
|---|
| 3 | #include <Interpreters/ColumnNamesContext.h> | 
|---|
| 4 | #include <Interpreters/InDepthNodeVisitor.h> | 
|---|
| 5 |  | 
|---|
| 6 | namespace DB | 
|---|
| 7 | { | 
|---|
| 8 |  | 
|---|
| 9 | namespace ErrorCodes | 
|---|
| 10 | { | 
|---|
| 11 | extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; | 
|---|
| 12 | } | 
|---|
| 13 |  | 
|---|
| 14 | class ASTIdentifier; | 
|---|
| 15 | class ASTFunction; | 
|---|
| 16 | class ASTSelectQuery; | 
|---|
| 17 | struct ASTTablesInSelectQueryElement; | 
|---|
| 18 | struct ASTArrayJoin; | 
|---|
| 19 | struct ASTTableExpression; | 
|---|
| 20 |  | 
|---|
| 21 | class RequiredSourceColumnsMatcher | 
|---|
| 22 | { | 
|---|
| 23 | public: | 
|---|
| 24 | using Visitor = ConstInDepthNodeVisitor<RequiredSourceColumnsMatcher, false>; | 
|---|
| 25 | using Data = ColumnNamesContext; | 
|---|
| 26 |  | 
|---|
| 27 | static bool needChildVisit(const ASTPtr & node, const ASTPtr & child); | 
|---|
| 28 | static void visit(const ASTPtr & ast, Data & data); | 
|---|
| 29 |  | 
|---|
| 30 | private: | 
|---|
| 31 | static void visit(const ASTIdentifier & node, const ASTPtr &, Data & data); | 
|---|
| 32 | static void visit(const ASTFunction & node, const ASTPtr &, Data & data); | 
|---|
| 33 | static void visit(const ASTTablesInSelectQueryElement & node, const ASTPtr &, Data & data); | 
|---|
| 34 | static void visit(const ASTTableExpression & node, const ASTPtr &, Data & data); | 
|---|
| 35 | static void visit(const ASTArrayJoin & node, const ASTPtr &, Data & data); | 
|---|
| 36 | static void visit(const ASTSelectQuery & select, const ASTPtr &, Data & data); | 
|---|
| 37 | }; | 
|---|
| 38 |  | 
|---|
| 39 | /// Extracts all the information about columns and tables from ASTSelectQuery block into ColumnNamesContext object. | 
|---|
| 40 | /// It doesn't use anything but AST. It visits nodes from bottom to top except ASTFunction content to get aliases in right manner. | 
|---|
| 41 | /// @note There's some ambiguousness with nested columns names that can't be solved without schema. | 
|---|
| 42 | using RequiredSourceColumnsVisitor = RequiredSourceColumnsMatcher::Visitor; | 
|---|
| 43 |  | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|