2018-10-16 19:00:05 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-12-26 14:43:25 +00:00
|
|
|
#include <Interpreters/ColumnNamesContext.h>
|
|
|
|
#include <Interpreters/InDepthNodeVisitor.h>
|
2018-11-10 20:09:07 +00:00
|
|
|
|
2018-10-16 19:00:05 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2018-11-10 20:09:07 +00:00
|
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
2018-10-16 19:00:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-26 14:43:25 +00:00
|
|
|
class ASTIdentifier;
|
|
|
|
class ASTFunction;
|
|
|
|
class ASTSelectQuery;
|
|
|
|
struct ASTTablesInSelectQueryElement;
|
|
|
|
struct ASTArrayJoin;
|
|
|
|
struct ASTTableExpression;
|
|
|
|
|
2018-12-07 16:28:20 +00:00
|
|
|
class RequiredSourceColumnsMatcher
|
2018-10-16 19:00:05 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-02-22 13:33:56 +00:00
|
|
|
using Visitor = InDepthNodeVisitor<RequiredSourceColumnsMatcher, false>;
|
2018-12-26 14:43:25 +00:00
|
|
|
using Data = ColumnNamesContext;
|
2018-12-07 16:28:20 +00:00
|
|
|
|
2018-12-26 14:43:25 +00:00
|
|
|
static bool needChildVisit(ASTPtr & node, const ASTPtr & child);
|
2019-02-22 13:33:56 +00:00
|
|
|
static void visit(ASTPtr & ast, Data & data);
|
2018-10-16 19:00:05 +00:00
|
|
|
|
|
|
|
private:
|
2018-12-26 14:43:25 +00:00
|
|
|
static void visit(const ASTIdentifier & node, const ASTPtr &, Data & data);
|
|
|
|
static void visit(const ASTFunction & node, const ASTPtr &, Data & data);
|
|
|
|
static void visit(ASTTablesInSelectQueryElement & node, const ASTPtr &, Data & data);
|
2019-02-22 13:33:56 +00:00
|
|
|
static void visit(ASTTableExpression & node, const ASTPtr &, Data & data);
|
|
|
|
static void visit(const ASTArrayJoin & node, const ASTPtr &, Data & data);
|
|
|
|
static void visit(ASTSelectQuery & select, const ASTPtr &, Data & data);
|
2018-10-16 19:00:05 +00:00
|
|
|
};
|
|
|
|
|
2018-12-26 14:43:25 +00:00
|
|
|
/// Extracts all the information about columns and tables from ASTSelectQuery block into ColumnNamesContext object.
|
2018-12-26 20:35:06 +00:00
|
|
|
/// It doesn't use anything but AST. It visits nodes from bottom to top except ASTFunction content to get aliases in right manner.
|
2018-12-26 14:43:25 +00:00
|
|
|
/// @note There's some ambiguousness with nested columns names that can't be solved without schema.
|
2019-02-22 13:33:56 +00:00
|
|
|
using RequiredSourceColumnsVisitor = RequiredSourceColumnsMatcher::Visitor;
|
2018-12-07 16:28:20 +00:00
|
|
|
|
2018-10-16 19:00:05 +00:00
|
|
|
}
|