-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParseAttributeDefinition.hpp
255 lines (215 loc) · 6.97 KB
/
ParseAttributeDefinition.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/**
* 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_ATTRIBUTE_DEFINITION_HPP_
#define QUICKSTEP_PARSER_PARSE_ATTRIBUTE_DEFINITION_HPP_
#include <memory>
#include <string>
#include <vector>
#include "parser/ParseString.hpp"
#include "parser/ParseTreeNode.hpp"
#include "utility/Macros.hpp"
namespace quickstep {
class ParseColumnConstraint;
class Type;
template <class T> class PtrList;
/** \addtogroup Parser
* @{
*/
/**
* @brief Parsed representation of a data type.
**/
class ParseDataType {
public:
/**
* @brief Constructor.
*
* @param type The Type of the data.
**/
explicit ParseDataType(const Type &type)
: type_(&type) {
}
/**
* @brief Get the type.
*
* @return The Type.
**/
const Type& getType() const {
return *type_;
}
private:
// Use a pointer instead of a reference so that it may be modified by column
// constraints.
const Type *type_;
friend class ParseColumnConstraintNull;
friend class ParseColumnConstraintNotNull;
DISALLOW_COPY_AND_ASSIGN(ParseDataType);
};
/**
* @brief Parsed representation of an attribute definition
**/
class ParseAttributeDefinition : public ParseTreeNode {
public:
/**
* @brief Constructor
*
* @param line_number Line number of the first token of this node in the SQL statement.
* @param column_number Column number of the first token of this node in the SQL statement.
* @param name The attribute name.
* @param data_type The parsed data type (becomes owned by this
* ParseAttributeDefinition).
* @param constraint_list An optional list of column constraints (may be NULL
* if no constraints).
**/
ParseAttributeDefinition(const int line_number,
const int column_number,
ParseString *name,
ParseDataType *data_type,
PtrList<ParseColumnConstraint> *constraint_list);
/**
* @brief Destructor
**/
~ParseAttributeDefinition() override {}
std::string getName() const override {
return "AttributeDefinition";
}
/**
* @brief Get the attribute name
*
* @return The attribute name
**/
const ParseString* name() const {
return name_.get();
}
/**
* @brief Get the parsed data type
*
* @return The data type
**/
const ParseDataType& data_type() const {
return *data_type_;
}
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;
private:
std::unique_ptr<ParseString> name_;
std::unique_ptr<ParseDataType> data_type_;
friend class ParseColumnConstraintNull;
friend class ParseColumnConstraintNotNull;
DISALLOW_COPY_AND_ASSIGN(ParseAttributeDefinition);
};
/**
* @brief A column constraint that can be applied to an attribute definition.
**/
class ParseColumnConstraint : public ParseTreeNode {
public:
/**
* @brief Virtual destructor.
**/
~ParseColumnConstraint() override {
}
/**
* @brief Apply this constraint to an attribute definition.
*
* @param target The attribute definition to modify with this constraint.
**/
virtual void applyTo(ParseAttributeDefinition *target) const = 0;
protected:
ParseColumnConstraint(const int line_number, const int column_number)
: ParseTreeNode(line_number, column_number) {
}
private:
DISALLOW_COPY_AND_ASSIGN(ParseColumnConstraint);
};
/**
* @brief A column constraint allowing NULL values.
**/
class ParseColumnConstraintNull: public ParseColumnConstraint {
public:
/**
* @brief Constructor.
*
* @param line_number Line number of the first token of this node in the SQL statement.
* @param column_number Column number of the first token of this node in the SQL statement.
**/
ParseColumnConstraintNull(const int line_number, const int column_number)
: ParseColumnConstraint(line_number, column_number) {
}
/**
* @brief Destructor.
*/
~ParseColumnConstraintNull() override {
}
std::string getName() const override {
return "NullablityColumnConstraint";
}
void applyTo(ParseAttributeDefinition *target) const override;
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;
private:
DISALLOW_COPY_AND_ASSIGN(ParseColumnConstraintNull);
};
/**
* @brief A column constraint disallowing NULL values.
**/
class ParseColumnConstraintNotNull: public ParseColumnConstraint {
public:
/**
* @brief Constructor.
*
* @param line_number Line number of the first token of this node in the SQL statement.
* @param column_number Column number of the first token of this node in the SQL statement.
**/
ParseColumnConstraintNotNull(const int line_number, const int column_number)
: ParseColumnConstraint(line_number, column_number) {
}
/**
* @brief Destructor.
*/
~ParseColumnConstraintNotNull() override {
}
std::string getName() const override {
return "NullablityColumnConstraint";
}
void applyTo(ParseAttributeDefinition *target) const override;
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;
private:
DISALLOW_COPY_AND_ASSIGN(ParseColumnConstraintNotNull);
};
/** @} */
} // namespace quickstep
#endif // QUICKSTEP_PARSER_PARSE_ATTRIBUTE_DEFINITION_HPP_