ClickHouse/src/Interpreters/PredicateRewriteVisitor.h

50 lines
1.4 KiB
C++
Raw Normal View History

2019-12-18 03:56:03 +00:00
#pragma once
#include <Interpreters/Context_fwd.h>
#include <Interpreters/DatabaseAndTableWithAlias.h>
#include <Interpreters/InDepthNodeVisitor.h>
2019-12-18 03:56:03 +00:00
#include <Parsers/ASTSelectQuery.h>
#include <Parsers/ASTSelectWithUnionQuery.h>
#include <Parsers/IAST.h>
2019-12-18 03:56:03 +00:00
namespace DB
{
class PredicateRewriteVisitorData : WithConstContext
2019-12-18 03:56:03 +00:00
{
public:
bool is_rewrite = false;
2019-12-18 03:56:03 +00:00
using TypeToVisit = ASTSelectWithUnionQuery;
void visit(ASTSelectWithUnionQuery & union_select_query, ASTPtr &);
static bool needChild(const ASTPtr & node, const ASTPtr &)
{
return !(node && node->as<TypeToVisit>());
}
PredicateRewriteVisitorData(
ContextConstPtr context_,
const ASTs & predicates_,
const TableWithColumnNamesAndTypes & table_columns_,
bool optimize_final_,
bool optimize_with_);
2019-12-18 03:56:03 +00:00
private:
const ASTs & predicates;
const TableWithColumnNamesAndTypes & table_columns;
2019-12-18 03:56:03 +00:00
bool optimize_final;
bool optimize_with;
2019-12-18 03:56:03 +00:00
void visitFirstInternalSelect(ASTSelectQuery & select_query, ASTPtr &);
void visitOtherInternalSelect(ASTSelectQuery & select_query, ASTPtr &);
bool rewriteSubquery(ASTSelectQuery & subquery, const Names & inner_columns);
2019-12-18 03:56:03 +00:00
};
using PredicateRewriteMatcher = OneTypeMatcher<PredicateRewriteVisitorData, PredicateRewriteVisitorData::needChild>;
2019-12-18 03:56:03 +00:00
using PredicateRewriteVisitor = InDepthNodeVisitor<PredicateRewriteMatcher, true>;
2019-12-18 03:56:03 +00:00
}