-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParseWindow.hpp
203 lines (178 loc) · 6.6 KB
/
ParseWindow.hpp
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
**/
#ifndef QUICKSTEP_PARSER_PARSE_WINDOW_HPP_
#define QUICKSTEP_PARSER_PARSE_WINDOW_HPP_
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
#include "parser/ParseExpression.hpp"
#include "parser/ParseOrderBy.hpp"
#include "parser/ParseString.hpp"
#include "parser/ParseTreeNode.hpp"
#include "utility/PtrList.hpp"
namespace quickstep {
/**
* @brief The information of the how the framing in the window is defined
**/
struct ParseFrameInfo : ParseTreeNode {
/**
* @brief Constructor.
* @param row True if the frame mode is ROW, false if it is RANGE.
* @param num_pre The number of rows/value of range that is preceding
* the current row in the frame.
* @param num_follow The number of rows/value of range that is following
* the current row in the frame.
**/
ParseFrameInfo(const int line_number,
const int column_number,
const bool is_row_in,
const std::int64_t num_preceding_in,
const std::int64_t num_following_in)
: ParseTreeNode(line_number, column_number),
is_row(is_row_in),
num_preceding(num_preceding_in),
num_following(num_following_in) {
}
std::string getName() const override { return "FrameInfo"; }
const bool is_row;
const std::int64_t num_preceding;
const std::int64_t num_following;
protected:
void getFieldStringItems(
std::vector<std::string> *inline_field_names,
std::vector<std::string> *inline_field_values,
std::vector<std::string> *non_container_child_field_names,
std::vector<const ParseTreeNode *> *non_container_child_fields,
std::vector<std::string> *container_child_field_names,
std::vector<std::vector<const ParseTreeNode *>> *container_child_fields)
const override {
inline_field_names->push_back("frame_mode");
inline_field_values->push_back(is_row ? "row" : "range");
inline_field_names->push_back("num_preceding");
inline_field_values->push_back(std::to_string(num_preceding));
inline_field_names->push_back("num_following");
inline_field_values->push_back(std::to_string(num_following));
}
};
/**
* @brief The parsed representation of a WINDOW definition.
**/
class ParseWindow : public ParseTreeNode {
public:
/**
* @brief Constructor.
* @param line_number The line number of the first token of this WINDOW clause
* in the SQL statement.
* @param column_number The column number of the first token of this WINDOW
* clause in the SQL statement.
* @param partition_by_expressions Optional grouping expressions that might be
* specified in the SQL statement. Similar to
* GROUP BY with regular aggregates.
* @param order_by_expressions Optional ordering expressions that might be
* specified in the SQL statement.
* @param frame_info The information about framing.
**/
ParseWindow(const int line_number,
const int column_number,
PtrList<ParseExpression> *partition_by_expressions,
PtrList<ParseOrderByItem> *order_by_expressions,
ParseFrameInfo *frame_info)
: ParseTreeNode(line_number, column_number),
partition_by_expressions_(partition_by_expressions),
order_by_expressions_(order_by_expressions),
frame_info_(frame_info) {
}
/**
* @brief Destructor.
**/
~ParseWindow() override {}
std::string getName() const override {
return "window";
}
/**
* @brief Grouping expressions.
**/
const PtrList<ParseExpression>* partition_by_expressions() const {
return partition_by_expressions_.get();
}
/**
* @brief Ordering expressions.
**/
const PtrList<ParseOrderByItem>* order_by_expressions() const {
return order_by_expressions_.get();
}
/**
* @brief Frame information.
**/
const ParseFrameInfo* frame_info() const {
return frame_info_.get();
}
/**
* @return The window name.
*/
const ParseString* name() const {
return name_.get();
}
/**
* @brief Set the name of the window.
* @param name The name of the window.
**/
void setName(ParseString *name) {
name_.reset(name);
}
protected:
void getFieldStringItems(
std::vector<std::string> *inline_field_names,
std::vector<std::string> *inline_field_values,
std::vector<std::string> *non_container_child_field_names,
std::vector<const ParseTreeNode *> *non_container_child_fields,
std::vector<std::string> *container_child_field_names,
std::vector<std::vector<const ParseTreeNode *>> *container_child_fields) const override {
if (name_ != nullptr) {
inline_field_names->push_back("window_name");
inline_field_values->push_back(name_->value());
}
container_child_field_names->push_back("partition_by");
container_child_fields->emplace_back();
if (partition_by_expressions_ != nullptr) {
for (const auto &e : *partition_by_expressions_) {
container_child_fields->back().emplace_back(&e);
}
}
container_child_field_names->push_back("order_by");
container_child_fields->emplace_back();
if (order_by_expressions_ != nullptr) {
for (const auto &e : *order_by_expressions_) {
container_child_fields->back().emplace_back(&e);
}
}
if (frame_info_ != nullptr) {
non_container_child_field_names->push_back("frame_info");
non_container_child_fields->push_back(frame_info_.get());
}
}
private:
std::unique_ptr<PtrList<ParseExpression>> partition_by_expressions_;
std::unique_ptr<PtrList<ParseOrderByItem>> order_by_expressions_;
std::unique_ptr<ParseFrameInfo> frame_info_;
std::unique_ptr<ParseString> name_;
};
} // namespace quickstep
#endif // QUICKSTEP_PARSER_PARSE_WINDOW_HPP_