1 #ifndef __GPUDB__GENERICRECORD_HPP__
2 #define __GPUDB__GENERICRECORD_HPP__
6 #include <avro/Schema.hh>
7 #include <avro/Specific.hh>
9 #include <boost/core/demangle.hpp>
10 #include <boost/lexical_cast.hpp>
21 friend struct ::avro::codec_traits<GenericRecord>;
28 const ::avro::ValidSchema&
getSchema()
const;
30 template<
typename T> T&
value(
const size_t index)
32 T* o = boost::any_cast<T>(&m_values.at(index));
33 if (!o)
throw std::runtime_error(
"Error converting GenericRecord column " + boost::lexical_cast<std::string>(index) +
" to type " + boost::core::demangle(
typeid(T).name() ));
37 template<
typename T>
const T&
value(
const size_t index)
const
39 const T* o = boost::any_cast<T>(&m_values.at(index));
40 if (!o)
throw std::runtime_error(
"Error converting GenericRecord column " + boost::lexical_cast<std::string>(index) +
" to type " + boost::core::demangle(
typeid(T).name() ));
44 template<
typename T> T&
value(
const std::string& name)
47 if (!o)
throw std::runtime_error(
"Error converting GenericRecord column '" + name +
"' to type " + boost::core::demangle(
typeid(T).name() ));
51 template<
typename T>
const T&
value(
const std::string& name)
const
53 const T* o = boost::any_cast<T>(&m_values[m_type.
getColumnIndex(name)]);
54 if (!o)
throw std::runtime_error(
"Error converting GenericRecord column '" + name +
"' to type " + boost::core::demangle(
typeid(T).name() ));
58 std::vector<uint8_t>&
bytesValue(
const size_t index);
59 const std::vector<uint8_t>&
bytesValue(
const size_t index)
const;
60 std::vector<uint8_t>&
bytesValue(
const std::string& name);
61 const std::vector<uint8_t>&
bytesValue(
const std::string& name)
const;
64 const double&
doubleValue(
const size_t index)
const;
66 const double&
doubleValue(
const std::string& name)
const;
69 const float&
floatValue(
const size_t index)
const;
71 const float&
floatValue(
const std::string& name)
const;
73 int32_t&
intValue(
const size_t index);
74 const int32_t&
intValue(
const size_t index)
const;
75 int32_t&
intValue(
const std::string& name);
76 const int32_t&
intValue(
const std::string& name)
const;
79 const int64_t&
longValue(
const size_t index)
const;
80 int64_t&
longValue(
const std::string& name);
81 const int64_t&
longValue(
const std::string& name)
const;
84 const std::string&
stringValue(
const size_t index)
const;
86 const std::string&
stringValue(
const std::string& name)
const;
89 const boost::optional<std::vector<uint8_t> >&
nullableBytesValue(
const size_t index)
const;
91 const boost::optional<std::vector<uint8_t> >&
nullableBytesValue(
const std::string& name)
const;
106 const boost::optional<int32_t>&
nullableIntValue(
const std::string& name)
const;
111 const boost::optional<int64_t>&
nullableLongValue(
const std::string& name)
const;
118 bool isNull(
const size_t index)
const;
119 bool isNull(
const std::string& name)
const;
121 void getAsBytes(
const size_t index, std::vector<uint8_t>& result)
const;
122 void getAsBytes(
const std::string& name, std::vector<uint8_t>& result)
const;
123 std::vector<uint8_t>
getAsBytes(
const size_t index)
const;
124 std::vector<uint8_t>
getAsBytes(
const std::string& name)
const;
126 void getAsDouble(
const size_t index,
double& result)
const;
127 void getAsDouble(
const std::string& name,
double& result)
const;
131 void getAsFloat(
const size_t index,
float& result)
const;
132 void getAsFloat(
const std::string& name,
float& result)
const;
134 float getAsFloat(
const std::string& name)
const;
136 void getAsInt(
const size_t index, int32_t& result)
const;
137 void getAsInt(
const std::string& name, int32_t& result)
const;
138 int32_t
getAsInt(
const size_t index)
const;
139 int32_t
getAsInt(
const std::string& name)
const;
141 void getAsLong(
const size_t index, int64_t& result)
const;
142 void getAsLong(
const std::string& name, int64_t& result)
const;
143 int64_t
getAsLong(
const size_t index)
const;
144 int64_t
getAsLong(
const std::string& name)
const;
146 void getAsString(
const size_t index, std::string& result)
const;
147 void getAsString(
const std::string& name, std::string& result)
const;
149 std::string
getAsString(
const std::string& name)
const;
151 void getAsNullableBytes(
const size_t index, boost::optional<std::vector<uint8_t> >& result)
const;
152 void getAsNullableBytes(
const std::string& name, boost::optional<std::vector<uint8_t> >& result)
const;
154 boost::optional<std::vector<uint8_t> >
getAsNullableBytes(
const std::string& name)
const;
162 void getAsNullableFloat(
const std::string& name, boost::optional<float>& result)
const;
166 void getAsNullableInt(
const size_t index, boost::optional<int32_t>& result)
const;
167 void getAsNullableInt(
const std::string& name, boost::optional<int32_t>& result)
const;
171 void getAsNullableLong(
const size_t index, boost::optional<int64_t>& result)
const;
172 void getAsNullableLong(
const std::string& name, boost::optional<int64_t>& result)
const;
177 void getAsNullableString(
const std::string& name, boost::optional<std::string>& result)
const;
181 void setNull(
const size_t index);
182 void setNull(
const std::string& name);
184 void setAsBytes(
const size_t index,
const std::vector<uint8_t>& newValue);
185 void setAsBytes(
const std::string& name,
const std::vector<uint8_t>& newValue);
187 void setAsDouble(
const size_t index,
const double& newValue);
188 void setAsDouble(
const std::string& name,
const double& newValue);
190 void setAsFloat(
const size_t index,
const float& newValue);
191 void setAsFloat(
const std::string& name,
const float& newValue);
193 void setAsInt(
const size_t index,
const int32_t& newValue);
194 void setAsInt(
const std::string& name,
const int32_t& newValue);
196 void setAsLong(
const size_t index,
const int64_t& newValue);
197 void setAsLong(
const std::string& name,
const int64_t& newValue);
199 void setAsString(
const size_t index,
const std::string& newValue);
200 void setAsString(
const std::string& name,
const std::string& newValue);
202 void setAsNullableBytes(
const size_t index,
const boost::optional<std::vector<uint8_t> >& newValue);
203 void setAsNullableBytes(
const std::string& name,
const boost::optional<std::vector<uint8_t> >& newValue);
206 void setAsNullableDouble(
const std::string& name,
const boost::optional<double>& newValue);
209 void setAsNullableFloat(
const std::string& name,
const boost::optional<float>& newValue);
211 void setAsNullableInt(
const size_t index,
const boost::optional<int32_t>& newValue);
212 void setAsNullableInt(
const std::string& name,
const boost::optional<int32_t>& newValue);
214 void setAsNullableLong(
const size_t index,
const boost::optional<int64_t>& newValue);
215 void setAsNullableLong(
const std::string& name,
const boost::optional<int64_t>& newValue);
217 void setAsNullableString(
const size_t index,
const boost::optional<std::string>& newValue);
218 void setAsNullableString(
const std::string& name,
const boost::optional<std::string>& newValue);
220 void toString(
const size_t index, std::string& result)
const;
221 void toString(
const std::string& name, std::string& result)
const;
222 std::string
toString(
const size_t index)
const;
223 std::string
toString(
const std::string& name)
const;
236 static void decode(
const std::string& schemaString,
const std::vector<std::vector<uint8_t> >& encodedData, std::vector<GenericRecord>& data );
245 static void decode(
const std::string& schemaString,
const std::vector<uint8_t>& encodedData,
GenericRecord& data );
250 std::vector<boost::any> m_values;
252 GenericRecord(
const std::vector<std::pair<Type::Column::ColumnType, bool> >& columnTypes);
255 static void transpose(
const std::string& schemaString,
const std::vector<uint8_t>& encodedData, std::vector<GenericRecord>& data,
gpudb_type_ptr_t &dataTypePtr );
264 template<>
struct codec_traits<gpudb::GenericRecord>
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)
Create a blank GenericRecord object from a given type.
T & value(const size_t index)
boost::shared_ptr< Type > gpudb_type_ptr_t
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
static void decode(const std::string &schemaString, const std::vector< std::vector< uint8_t > > &encodedData, std::vector< GenericRecord > &data)
Decodes avro encoded data (given the schema string) into GenericRecord objects.
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)
friend std::ostream & operator<<(std::ostream &os, GenericRecord &gr)
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)