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