GPUdb C++ API  Version 6.0.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
GenericRecord.hpp
Go to the documentation of this file.
1 #ifndef __GPUDB__GENERICRECORD_HPP__
2 #define __GPUDB__GENERICRECORD_HPP__
3 
4 #include "gpudb/Type.hpp"
5 
6 #include <avro/Schema.hh>
7 #include <avro/Specific.hh>
8 
9 namespace gpudb
10 {
12  {
13  friend class GPUdb;
14 
15  friend struct ::avro::codec_traits<GenericRecord>;
16 
17  public:
18  GenericRecord(const Type& type);
19  const Type& getType() const;
20  const ::avro::ValidSchema& getSchema() const;
21 
22  template<typename T> T& value(const size_t index)
23  {
24  return *boost::any_cast<T>(&m_values.at(index));
25  }
26 
27  template<typename T> const T& value(const size_t index) const
28  {
29  return *boost::any_cast<T>(&m_values.at(index));
30  }
31 
32  template<typename T> T& value(const std::string& name)
33  {
34  return *boost::any_cast<T>(&m_values[m_type.getColumnIndex(name)]);
35  }
36 
37  template<typename T> const T& value(const std::string& name) const
38  {
39  return *boost::any_cast<T>(&m_values[m_type.getColumnIndex(name)]);
40  }
41 
42  std::vector<uint8_t>& bytesValue(const size_t index);
43  const std::vector<uint8_t>& bytesValue(const size_t index) const;
44  std::vector<uint8_t>& bytesValue(const std::string& name);
45  const std::vector<uint8_t>& bytesValue(const std::string& name) const;
46 
47  double& doubleValue(const size_t index);
48  const double& doubleValue(const size_t index) const;
49  double& doubleValue(const std::string& name);
50  const double& doubleValue(const std::string& name) const;
51 
52  float& floatValue(const size_t index);
53  const float& floatValue(const size_t index) const;
54  float& floatValue(const std::string& name);
55  const float& floatValue(const std::string& name) const;
56 
57  int32_t& intValue(const size_t index);
58  const int32_t& intValue(const size_t index) const;
59  int32_t& intValue(const std::string& name);
60  const int32_t& intValue(const std::string& name) const;
61 
62  int64_t& longValue(const size_t index);
63  const int64_t& longValue(const size_t index) const;
64  int64_t& longValue(const std::string& name);
65  const int64_t& longValue(const std::string& name) const;
66 
67  std::string& stringValue(const size_t index);
68  const std::string& stringValue(const size_t index) const;
69  std::string& stringValue(const std::string& name);
70  const std::string& stringValue(const std::string& name) const;
71 
72  boost::optional<std::vector<uint8_t> >& nullableBytesValue(const size_t index);
73  const boost::optional<std::vector<uint8_t> >& nullableBytesValue(const size_t index) const;
74  boost::optional<std::vector<uint8_t> >& nullableBytesValue(const std::string& name);
75  const boost::optional<std::vector<uint8_t> >& nullableBytesValue(const std::string& name) const;
76 
77  boost::optional<double>& nullableDoubleValue(const size_t index);
78  const boost::optional<double>& nullableDoubleValue(const size_t index) const;
79  boost::optional<double>& nullableDoubleValue(const std::string& name);
80  const boost::optional<double>& nullableDoubleValue(const std::string& name) const;
81 
82  boost::optional<float>& nullableFloatValue(const size_t index);
83  const boost::optional<float>& nullableFloatValue(const size_t index) const;
84  boost::optional<float>& nullableFloatValue(const std::string& name);
85  const boost::optional<float>& nullableFloatValue(const std::string& name) const;
86 
87  boost::optional<int32_t>& nullableIntValue(const size_t index);
88  const boost::optional<int32_t>& nullableIntValue(const size_t index) const;
89  boost::optional<int32_t>& nullableIntValue(const std::string& name);
90  const boost::optional<int32_t>& nullableIntValue(const std::string& name) const;
91 
92  boost::optional<int64_t>& nullableLongValue(const size_t index);
93  const boost::optional<int64_t>& nullableLongValue(const size_t index) const;
94  boost::optional<int64_t>& nullableLongValue(const std::string& name);
95  const boost::optional<int64_t>& nullableLongValue(const std::string& name) const;
96 
97  boost::optional<std::string>& nullableStringValue(const size_t index);
98  const boost::optional<std::string>& nullableStringValue(const size_t index) const;
99  boost::optional<std::string>& nullableStringValue(const std::string& name);
100  const boost::optional<std::string>& nullableStringValue(const std::string& name) const;
101 
102  bool isNull(const size_t index) const;
103  bool isNull(const std::string& name) const;
104 
105  void getAsBytes(const size_t index, std::vector<uint8_t>& result) const;
106  void getAsBytes(const std::string& name, std::vector<uint8_t>& result) const;
107  std::vector<uint8_t> getAsBytes(const size_t index) const;
108  std::vector<uint8_t> getAsBytes(const std::string& name) const;
109 
110  void getAsDouble(const size_t index, double& result) const;
111  void getAsDouble(const std::string& name, double& result) const;
112  double getAsDouble(const size_t index) const;
113  double getAsDouble(const std::string& name) const;
114 
115  void getAsFloat(const size_t index, float& result) const;
116  void getAsFloat(const std::string& name, float& result) const;
117  float getAsFloat(const size_t index) const;
118  float getAsFloat(const std::string& name) const;
119 
120  void getAsInt(const size_t index, int32_t& result) const;
121  void getAsInt(const std::string& name, int32_t& result) const;
122  int32_t getAsInt(const size_t index) const;
123  int32_t getAsInt(const std::string& name) const;
124 
125  void getAsLong(const size_t index, int64_t& result) const;
126  void getAsLong(const std::string& name, int64_t& result) const;
127  int64_t getAsLong(const size_t index) const;
128  int64_t getAsLong(const std::string& name) const;
129 
130  void getAsString(const size_t index, std::string& result) const;
131  void getAsString(const std::string& name, std::string& result) const;
132  std::string getAsString(const size_t index) const;
133  std::string getAsString(const std::string& name) const;
134 
135  void getAsNullableBytes(const size_t index, boost::optional<std::vector<uint8_t> >& result) const;
136  void getAsNullableBytes(const std::string& name, boost::optional<std::vector<uint8_t> >& result) const;
137  boost::optional<std::vector<uint8_t> > getAsNullableBytes(const size_t index) const;
138  boost::optional<std::vector<uint8_t> > getAsNullableBytes(const std::string& name) const;
139 
140  void getAsNullableDouble(const size_t index, boost::optional<double>& result) const;
141  void getAsNullableDouble(const std::string& name, boost::optional<double>& result) const;
142  boost::optional<double> getAsNullableDouble(const size_t index) const;
143  boost::optional<double> getAsNullableDouble(const std::string& name) const;
144 
145  void getAsNullableFloat(const size_t index, boost::optional<float>& result) const;
146  void getAsNullableFloat(const std::string& name, boost::optional<float>& result) const;
147  boost::optional<float> getAsNullableFloat(const size_t index) const;
148  boost::optional<float> getAsNullableFloat(const std::string& name) const;
149 
150  void getAsNullableInt(const size_t index, boost::optional<int32_t>& result) const;
151  void getAsNullableInt(const std::string& name, boost::optional<int32_t>& result) const;
152  boost::optional<int32_t> getAsNullableInt(const size_t index) const;
153  boost::optional<int32_t> getAsNullableInt(const std::string& name) const;
154 
155  void getAsNullableLong(const size_t index, boost::optional<int64_t>& result) const;
156  void getAsNullableLong(const std::string& name, boost::optional<int64_t>& result) const;
157  boost::optional<int64_t> getAsNullableLong(const size_t index) const;
158  boost::optional<int64_t> getAsNullableLong(const std::string& name) const;
159 
160  void getAsNullableString(const size_t index, boost::optional<std::string>& result) const;
161  void getAsNullableString(const std::string& name, boost::optional<std::string>& result) const;
162  boost::optional<std::string> getAsNullableString(const size_t index) const;
163  boost::optional<std::string> getAsNullableString(const std::string& name) const;
164 
165  void setNull(const size_t index);
166  void setNull(const std::string& name);
167 
168  void setAsBytes(const size_t index, const std::vector<uint8_t>& newValue);
169  void setAsBytes(const std::string& name, const std::vector<uint8_t>& newValue);
170 
171  void setAsDouble(const size_t index, const double& newValue);
172  void setAsDouble(const std::string& name, const double& newValue);
173 
174  void setAsFloat(const size_t index, const float& newValue);
175  void setAsFloat(const std::string& name, const float& newValue);
176 
177  void setAsInt(const size_t index, const int32_t& newValue);
178  void setAsInt(const std::string& name, const int32_t& newValue);
179 
180  void setAsLong(const size_t index, const int64_t& newValue);
181  void setAsLong(const std::string& name, const int64_t& newValue);
182 
183  void setAsString(const size_t index, const std::string& newValue);
184  void setAsString(const std::string& name, const std::string& newValue);
185 
186  void setAsNullableBytes(const size_t index, const boost::optional<std::vector<uint8_t> >& newValue);
187  void setAsNullableBytes(const std::string& name, const boost::optional<std::vector<uint8_t> >& newValue);
188 
189  void setAsNullableDouble(const size_t index, const boost::optional<double>& newValue);
190  void setAsNullableDouble(const std::string& name, const boost::optional<double>& newValue);
191 
192  void setAsNullableFloat(const size_t index, const boost::optional<float>& newValue);
193  void setAsNullableFloat(const std::string& name, const boost::optional<float>& newValue);
194 
195  void setAsNullableInt(const size_t index, const boost::optional<int32_t>& newValue);
196  void setAsNullableInt(const std::string& name, const boost::optional<int32_t>& newValue);
197 
198  void setAsNullableLong(const size_t index, const boost::optional<int64_t>& newValue);
199  void setAsNullableLong(const std::string& name, const boost::optional<int64_t>& newValue);
200 
201  void setAsNullableString(const size_t index, const boost::optional<std::string>& newValue);
202  void setAsNullableString(const std::string& name, const boost::optional<std::string>& newValue);
203 
204  void toString(const size_t index, std::string& result) const;
205  void toString(const std::string& name, std::string& result) const;
206  std::string toString(const size_t index) const;
207  std::string toString(const std::string& name) const;
208 
209  private:
210  static void transpose(const std::string& schemaString, const std::vector<uint8_t>& encodedData, std::vector<GenericRecord>& data);
211 
212  Type m_type;
213  std::vector<boost::any> m_values;
214 
215  GenericRecord(const std::vector<std::pair<Type::Column::ColumnType, bool> >& columnTypes);
216  void initializeColumn(const Type::Column::ColumnType type, const bool isNullable);
217  };
218 
220 }
221 
222 namespace avro
223 {
224  template<> struct codec_traits<gpudb::GenericRecord>
225  {
226  static void encode(Encoder& e, const gpudb::GenericRecord& v);
227  static void decode(Decoder& d, gpudb::GenericRecord& v);
228  };
229 }
230 
231 #endif
void setAsBytes(const size_t index, const std::vector< uint8_t > &newValue)
void setAsFloat(const size_t index, const float &newValue)
void setAsNullableFloat(const size_t index, const boost::optional< float > &newValue)
GenericRecord(const Type &type)
T & value(const size_t index)
void getAsNullableLong(const size_t index, boost::optional< int64_t > &result) const
boost::optional< double > & nullableDoubleValue(const size_t index)
void toString(const size_t index, std::string &result) const
int32_t & intValue(const size_t index)
boost::optional< int32_t > & nullableIntValue(const size_t index)
void setAsDouble(const size_t index, const double &newValue)
const T & value(const size_t index) const
size_t getColumnIndex(const std::string &name) const
GenericRecord DynamicTableRecord
bool isNull(const size_t index) const
void setAsNullableLong(const size_t index, const boost::optional< int64_t > &newValue)
void getAsNullableInt(const size_t index, boost::optional< int32_t > &result) const
std::string & stringValue(const size_t index)
void getAsLong(const size_t index, int64_t &result) const
void getAsNullableFloat(const size_t index, boost::optional< float > &result) const
void setAsNullableInt(const size_t index, const boost::optional< int32_t > &newValue)
void setAsNullableDouble(const size_t index, const boost::optional< double > &newValue)
void setAsString(const size_t index, const std::string &newValue)
boost::optional< int64_t > & nullableLongValue(const size_t index)
void getAsNullableString(const size_t index, boost::optional< std::string > &result) const
boost::optional< float > & nullableFloatValue(const size_t index)
float & floatValue(const size_t index)
int64_t & longValue(const size_t index)
void getAsNullableDouble(const size_t index, boost::optional< double > &result) const
void getAsBytes(const size_t index, std::vector< uint8_t > &result) const
void getAsFloat(const size_t index, float &result) const
const Type & getType() const
void setAsLong(const size_t index, const int64_t &newValue)
const T & value(const std::string &name) const
double & doubleValue(const size_t index)
void getAsInt(const size_t index, int32_t &result) const
void setAsNullableBytes(const size_t index, const boost::optional< std::vector< uint8_t > > &newValue)
boost::optional< std::string > & nullableStringValue(const size_t index)
void setNull(const size_t index)
void getAsNullableBytes(const size_t index, boost::optional< std::vector< uint8_t > > &result) const
const ::avro::ValidSchema & getSchema() const
T & value(const std::string &name)
boost::optional< std::vector< uint8_t > > & nullableBytesValue(const size_t index)
void getAsString(const size_t index, std::string &result) const
void setAsNullableString(const size_t index, const boost::optional< std::string > &newValue)
void getAsDouble(const size_t index, double &result) const
void setAsInt(const size_t index, const int32_t &newValue)
std::vector< uint8_t > & bytesValue(const size_t index)