blob: 44b24d09c5d2e23ffbc5e65337beac5115fb4ffb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
#pragma once
#include <Core/Names.h>
#include <Core/NamesAndTypes.h>
#include <Interpreters/Context_fwd.h>
#include <Interpreters/Set.h>
#include <Interpreters/PreparedSets.h>
#include <Analyzer/IQueryTreeNode.h>
#include <Planner/TableExpressionData.h>
namespace DB
{
/** Global planner context contains common objects that are shared between each planner context.
*
* 1. Column identifiers.
*/
class GlobalPlannerContext
{
public:
GlobalPlannerContext() = default;
/** Create column identifier for column node.
*
* Result column identifier is added into context.
*/
const ColumnIdentifier & createColumnIdentifier(const QueryTreeNodePtr & column_node);
/** Create column identifier for column and column source.
*
* Result column identifier is added into context.
*/
const ColumnIdentifier & createColumnIdentifier(const NameAndTypePair & column, const QueryTreeNodePtr & column_source_node);
/// Check if context has column identifier
bool hasColumnIdentifier(const ColumnIdentifier & column_identifier);
private:
std::unordered_set<ColumnIdentifier> column_identifiers;
};
using GlobalPlannerContextPtr = std::shared_ptr<GlobalPlannerContext>;
class PlannerContext
{
public:
/// Create planner context with query context and global planner context
PlannerContext(ContextMutablePtr query_context_, GlobalPlannerContextPtr global_planner_context_);
/// Get planner context query context
ContextPtr getQueryContext() const
{
return query_context;
}
/// Get planner context mutable query context
const ContextMutablePtr & getMutableQueryContext() const
{
return query_context;
}
/// Get planner context mutable query context
ContextMutablePtr & getMutableQueryContext()
{
return query_context;
}
/// Get global planner context
const GlobalPlannerContextPtr & getGlobalPlannerContext() const
{
return global_planner_context;
}
/// Get global planner context
GlobalPlannerContextPtr & getGlobalPlannerContext()
{
return global_planner_context;
}
/// Get or create table expression data for table expression node.
TableExpressionData & getOrCreateTableExpressionData(const QueryTreeNodePtr & table_expression_node);
/** Get table expression data.
* Exception is thrown if there are no table expression data for table expression node.
*/
const TableExpressionData & getTableExpressionDataOrThrow(const QueryTreeNodePtr & table_expression_node) const;
/** Get table expression data.
* Exception is thrown if there are no table expression data for table expression node.
*/
TableExpressionData & getTableExpressionDataOrThrow(const QueryTreeNodePtr & table_expression_node);
/** Get table expression data.
* Null is returned if there are no table expression data for table expression node.
*/
const TableExpressionData * getTableExpressionDataOrNull(const QueryTreeNodePtr & table_expression_node) const;
/** Get table expression data.
* Null is returned if there are no table expression data for table expression node.
*/
TableExpressionData * getTableExpressionDataOrNull(const QueryTreeNodePtr & table_expression_node);
/// Get table expression node to data map
const std::unordered_map<QueryTreeNodePtr, TableExpressionData> & getTableExpressionNodeToData() const
{
return table_expression_node_to_data;
}
/// Get table expression node to data map
std::unordered_map<QueryTreeNodePtr, TableExpressionData> & getTableExpressionNodeToData()
{
return table_expression_node_to_data;
}
/** Get column node identifier.
* For column node source check if table expression data is registered.
* If table expression data is not registered exception is thrown.
* In table expression data get column node identifier using column name.
*/
const ColumnIdentifier & getColumnNodeIdentifierOrThrow(const QueryTreeNodePtr & column_node) const;
/** Get column node identifier.
* For column node source check if table expression data is registered.
* If table expression data is not registered null is returned.
* In table expression data get column node identifier or null using column name.
*/
const ColumnIdentifier * getColumnNodeIdentifierOrNull(const QueryTreeNodePtr & column_node) const;
using SetKey = std::string;
/// Create set key for set source node
static SetKey createSetKey(const DataTypePtr & left_operand_type, const QueryTreeNodePtr & set_source_node);
PreparedSets & getPreparedSets() { return prepared_sets; }
private:
/// Query context
ContextMutablePtr query_context;
/// Global planner context
GlobalPlannerContextPtr global_planner_context;
/// Column node to column identifier
std::unordered_map<QueryTreeNodePtr, ColumnIdentifier> column_node_to_column_identifier;
/// Table expression node to data
std::unordered_map<QueryTreeNodePtr, TableExpressionData> table_expression_node_to_data;
/// Set key to set
PreparedSets prepared_sets;
};
using PlannerContextPtr = std::shared_ptr<PlannerContext>;
}
|