-
Notifications
You must be signed in to change notification settings - Fork 10
/
CatalogAttribute.hpp
198 lines (169 loc) · 5.15 KB
/
CatalogAttribute.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
/**
* 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_CATALOG_CATALOG_ATTRIBUTE_HPP_
#define QUICKSTEP_CATALOG_CATALOG_ATTRIBUTE_HPP_
#include <string>
#include "catalog/Catalog.pb.h"
#include "catalog/CatalogTypedefs.hpp"
#include "utility/Macros.hpp"
namespace quickstep {
class CatalogRelationSchema;
class Type;
/** \addtogroup Catalog
* @{
*/
/**
* @brief An attribute in a relation.
**/
class CatalogAttribute {
public:
/**
* @brief Create a new attribute.
*
* @param parent The relation this attribute belongs to.
* @param name This attribute's name.
* @param type This attribute's complete data type.
* @param id This attribute's ID (defaults to -1, which means invalid/unset).
* @param display_name A different name to display when printing values of
* this attribute out. Defaults to name.
**/
CatalogAttribute(CatalogRelationSchema *parent,
const std::string &name,
const Type &type,
const attribute_id id = -1,
const std::string &display_name = "")
: parent_(parent), id_(id), name_(name), display_name_(display_name), type_(&type) {
}
/**
* @brief Reconstruct an attribute from its serialized Protocol Buffer form.
*
* @param proto The Protocol Buffer serialization of an attribute,
* previously produced by getProto().
**/
explicit CatalogAttribute(const serialization::CatalogAttribute &proto);
/**
* @brief Get the parent relation.
*
* @return Parent relation.
**/
const CatalogRelationSchema& getParent() const {
return *parent_;
}
/**
* @brief Get a mutable pointer to the parent relation.
*
* @return Parent relation.
**/
CatalogRelationSchema* getParentMutable() {
return parent_;
}
/**
* @brief Get this attribute's ID.
*
* @return This attribute's ID.
**/
attribute_id getID() const {
return id_;
}
/**
* @brief Get this attribute's name.
*
* @return This attribute's name.
**/
const std::string& getName() const {
return name_;
}
/**
* @brief Get this attribute's display name (the name which would be printed
* to the screen).
*
* @return This attribute's display name.
**/
const std::string& getDisplayName() const {
if (display_name_.empty()) {
return name_;
} else {
return display_name_;
}
}
/**
* @brief Set this attribute's display name (the name which would be printed
* to the screen).
*/
void setDisplayName(const std::string &new_display_name) {
display_name_ = new_display_name;
}
/**
* @brief Get this attribute's type.
*
* @return This attribute's type.
**/
const Type& getType() const {
return *type_;
}
/**
* @brief Serialize the attribute as Protocol Buffer.
*
* @return The Protocol Buffer representation of the attribute.
**/
serialization::CatalogAttribute getProto() const;
/**
* @brief Check whether a serialization::CatalogAttribute is fully-formed and
* all parts are valid.
*
* @param proto A serialized Protocol Buffer representation of a CatalogAttribute,
* originally generated by getProto().
* @return Whether proto is fully-formed and valid.
**/
static bool ProtoIsValid(const serialization::CatalogAttribute &proto);
private:
/**
* @brief Set the parent CatalogRelationSchema for this attribute. Used by
* CatalogRelationSchema (a friend of this class) when adding a new
* attribute.
*
* @param parent The new parent for this CatalogAttribute.
**/
void setParent(CatalogRelationSchema *parent) {
parent_ = parent;
}
/**
* @brief Set the ID of this attribute. Used by CatalogRelationSchema (a
* friend of this class) when adding a new attribute.
*
* @param id The new ID for this CatalogAttribute.
**/
void setID(const attribute_id id) {
id_ = id;
}
CatalogRelationSchema *parent_;
// The attribute id in CatalogRelationSchema.
attribute_id id_;
// The internal attribute name.
const std::string name_;
// The external attribute name used to print on screen, if non-empty.
std::string display_name_;
// The attribute's underlying type.
const Type *type_;
friend class CatalogRelationSchema;
DISALLOW_COPY_AND_ASSIGN(CatalogAttribute);
};
/** @} */
} // namespace quickstep
#endif // QUICKSTEP_CATALOG_CATALOG_ATTRIBUTE_HPP_