2018-09-12 05:41:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <unordered_map>
|
2018-12-06 19:02:42 +00:00
|
|
|
#include <Interpreters/InDepthNodeVisitor.h>
|
2018-09-12 05:41:09 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-11-02 15:09:15 +00:00
|
|
|
class ASTSelectWithUnionQuery;
|
|
|
|
class ASTSubquery;
|
|
|
|
struct ASTTableExpression;
|
|
|
|
struct ASTArrayJoin;
|
|
|
|
|
2018-09-12 05:41:09 +00:00
|
|
|
using Aliases = std::unordered_map<String, ASTPtr>;
|
|
|
|
|
2018-12-06 19:02:42 +00:00
|
|
|
/// Visits AST node to collect aliases.
|
|
|
|
class QueryAliasesMatcher
|
2018-09-27 19:25:18 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-12-06 19:02:42 +00:00
|
|
|
struct Data
|
|
|
|
{
|
|
|
|
Aliases & aliases;
|
|
|
|
};
|
2018-09-27 19:25:18 +00:00
|
|
|
|
2018-12-07 12:34:40 +00:00
|
|
|
static constexpr const char * label = "QueryAliases";
|
2018-11-02 15:09:15 +00:00
|
|
|
|
2018-12-07 14:24:47 +00:00
|
|
|
static std::vector<ASTPtr *> visit(ASTPtr & ast, Data & data);
|
2018-12-06 19:02:42 +00:00
|
|
|
static bool needChildVisit(ASTPtr & node, const ASTPtr & child);
|
2018-11-02 15:09:15 +00:00
|
|
|
|
2018-12-06 19:02:42 +00:00
|
|
|
private:
|
2018-12-07 14:24:47 +00:00
|
|
|
static std::vector<ASTPtr *> visit(ASTSubquery & subquery, const ASTPtr & ast, Data & data);
|
|
|
|
static std::vector<ASTPtr *> visit(const ASTArrayJoin &, const ASTPtr & ast, Data & data);
|
2018-12-06 19:02:42 +00:00
|
|
|
static void visitOther(const ASTPtr & ast, Data & data);
|
2018-09-27 19:25:18 +00:00
|
|
|
};
|
2018-09-12 05:41:09 +00:00
|
|
|
|
2018-12-06 19:02:42 +00:00
|
|
|
/// Visits AST nodes and collect their aliases in one map (with links to source nodes).
|
|
|
|
using QueryAliasesVisitor = InDepthNodeVisitor<QueryAliasesMatcher, false>;
|
|
|
|
|
2018-09-12 05:41:09 +00:00
|
|
|
}
|