1#pragma once
2
3#include <Interpreters/ColumnNamesContext.h>
4#include <Interpreters/InDepthNodeVisitor.h>
5
6namespace DB
7{
8
9namespace ErrorCodes
10{
11 extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
12}
13
14class ASTIdentifier;
15class ASTFunction;
16class ASTSelectQuery;
17struct ASTTablesInSelectQueryElement;
18struct ASTArrayJoin;
19struct ASTTableExpression;
20
21class RequiredSourceColumnsMatcher
22{
23public:
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
30private:
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.
42using RequiredSourceColumnsVisitor = RequiredSourceColumnsMatcher::Visitor;
43
44}
45