1 #ifndef __GPUDB__GENERICRECORD_HPP__
2 #define __GPUDB__GENERICRECORD_HPP__
6 #include <avro/Schema.hh>
7 #include <avro/Specific.hh>
9 #include <boost/lexical_cast.hpp>
10 #if BOOST_VERSION >= 105600
11 #include <boost/core/demangle.hpp>
13 #include <boost/units/detail/utility.hpp>
14 namespace boost {
namespace core {
using boost::units::detail::demangle; } }
26 friend struct ::avro::codec_traits<GenericRecord>;
33 const ::avro::ValidSchema&
getSchema()
const;
35 template<
typename T> T&
value(
const size_t index)
37 T* o = boost::any_cast<T>(&m_values.at(index));
38 if (!o)
throw std::runtime_error(
"Error converting GenericRecord column " + boost::lexical_cast<std::string>(index) +
" to type " + boost::core::demangle(
typeid(T).name() ));
42 template<
typename T>
const T&
value(
const size_t index)
const
44 const T* o = boost::any_cast<T>(&m_values.at(index));
45 if (!o)
throw std::runtime_error(
"Error converting GenericRecord column " + boost::lexical_cast<std::string>(index) +
" to type " + boost::core::demangle(
typeid(T).name() ));
49 template<
typename T> T&
value(
const std::string& name)
52 if (!o)
throw std::runtime_error(
"Error converting GenericRecord column '" + name +
"' to type " + boost::core::demangle(
typeid(T).name() ));
56 template<
typename T>
const T&
value(
const std::string& name)
const
58 const T* o = boost::any_cast<T>(&m_values[m_type.
getColumnIndex(name)]);
59 if (!o)
throw std::runtime_error(
"Error converting GenericRecord column '" + name +
"' to type " + boost::core::demangle(
typeid(T).name() ));
63 std::vector<uint8_t>&
bytesValue(
const size_t index);
64 const std::vector<uint8_t>&
bytesValue(
const size_t index)
const;
65 std::vector<uint8_t>&
bytesValue(
const std::string& name);
66 const std::vector<uint8_t>&
bytesValue(
const std::string& name)
const;
69 const double&
doubleValue(
const size_t index)
const;
71 const double&
doubleValue(
const std::string& name)
const;
74 const float&
floatValue(
const size_t index)
const;
76 const float&
floatValue(
const std::string& name)
const;
78 int32_t&
intValue(
const size_t index);
79 const int32_t&
intValue(
const size_t index)
const;
80 int32_t&
intValue(
const std::string& name);
81 const int32_t&
intValue(
const std::string& name)
const;
84 const int64_t&
longValue(
const size_t index)
const;
85 int64_t&
longValue(
const std::string& name);
86 const int64_t&
longValue(
const std::string& name)
const;
89 const std::string&
stringValue(
const size_t index)
const;
91 const std::string&
stringValue(
const std::string& name)
const;
94 const boost::optional<std::vector<uint8_t> >&
nullableBytesValue(
const size_t index)
const;
96 const boost::optional<std::vector<uint8_t> >&
nullableBytesValue(
const std::string& name)
const;
111 const boost::optional<int32_t>&
nullableIntValue(
const std::string& name)
const;
116 const boost::optional<int64_t>&
nullableLongValue(
const std::string& name)
const;
123 bool isNull(
const size_t index)
const;
124 bool isNull(
const std::string& name)
const;
126 void getAsBytes(
const size_t index, std::vector<uint8_t>& result)
const;
127 void getAsBytes(
const std::string& name, std::vector<uint8_t>& result)
const;
128 std::vector<uint8_t>
getAsBytes(
const size_t index)
const;
129 std::vector<uint8_t>
getAsBytes(
const std::string& name)
const;
131 void getAsDouble(
const size_t index,
double& result)
const;
132 void getAsDouble(
const std::string& name,
double& result)
const;
136 void getAsFloat(
const size_t index,
float& result)
const;
137 void getAsFloat(
const std::string& name,
float& result)
const;
139 float getAsFloat(
const std::string& name)
const;
141 void getAsInt(
const size_t index, int32_t& result)
const;
142 void getAsInt(
const std::string& name, int32_t& result)
const;
143 int32_t
getAsInt(
const size_t index)
const;
144 int32_t
getAsInt(
const std::string& name)
const;
146 void getAsLong(
const size_t index, int64_t& result)
const;
147 void getAsLong(
const std::string& name, int64_t& result)
const;
148 int64_t
getAsLong(
const size_t index)
const;
149 int64_t
getAsLong(
const std::string& name)
const;
151 void getAsString(
const size_t index, std::string& result)
const;
152 void getAsString(
const std::string& name, std::string& result)
const;
154 std::string
getAsString(
const std::string& name)
const;
156 void getAsNullableBytes(
const size_t index, boost::optional<std::vector<uint8_t> >& result)
const;
157 void getAsNullableBytes(
const std::string& name, boost::optional<std::vector<uint8_t> >& result)
const;
159 boost::optional<std::vector<uint8_t> >
getAsNullableBytes(
const std::string& name)
const;
167 void getAsNullableFloat(
const std::string& name, boost::optional<float>& result)
const;
171 void getAsNullableInt(
const size_t index, boost::optional<int32_t>& result)
const;
172 void getAsNullableInt(
const std::string& name, boost::optional<int32_t>& result)
const;
176 void getAsNullableLong(
const size_t index, boost::optional<int64_t>& result)
const;
177 void getAsNullableLong(
const std::string& name, boost::optional<int64_t>& result)
const;
182 void getAsNullableString(
const std::string& name, boost::optional<std::string>& result)
const;
186 void setNull(
const size_t index);
187 void setNull(
const std::string& name);
189 void setAsBytes(
const size_t index,
const std::vector<uint8_t>& newValue);
190 void setAsBytes(
const std::string& name,
const std::vector<uint8_t>& newValue);
192 void setAsDouble(
const size_t index,
const double& newValue);
193 void setAsDouble(
const std::string& name,
const double& newValue);
195 void setAsFloat(
const size_t index,
const float& newValue);
196 void setAsFloat(
const std::string& name,
const float& newValue);
198 void setAsInt(
const size_t index,
const int32_t& newValue);
199 void setAsInt(
const std::string& name,
const int32_t& newValue);
201 void setAsLong(
const size_t index,
const int64_t& newValue);
202 void setAsLong(
const std::string& name,
const int64_t& newValue);
204 void setAsString(
const size_t index,
const std::string& newValue);
205 void setAsString(
const std::string& name,
const std::string& newValue);
207 void setAsNullableBytes(
const size_t index,
const boost::optional<std::vector<uint8_t> >& newValue);
208 void setAsNullableBytes(
const std::string& name,
const boost::optional<std::vector<uint8_t> >& newValue);
211 void setAsNullableDouble(
const std::string& name,
const boost::optional<double>& newValue);
214 void setAsNullableFloat(
const std::string& name,
const boost::optional<float>& newValue);
216 void setAsNullableInt(
const size_t index,
const boost::optional<int32_t>& newValue);
217 void setAsNullableInt(
const std::string& name,
const boost::optional<int32_t>& newValue);
219 void setAsNullableLong(
const size_t index,
const boost::optional<int64_t>& newValue);
220 void setAsNullableLong(
const std::string& name,
const boost::optional<int64_t>& newValue);
222 void setAsNullableString(
const size_t index,
const boost::optional<std::string>& newValue);
223 void setAsNullableString(
const std::string& name,
const boost::optional<std::string>& newValue);
225 void toString(
const size_t index, std::string& result)
const;
226 void toString(
const std::string& name, std::string& result)
const;
227 std::string
toString(
const size_t index)
const;
228 std::string
toString(
const std::string& name)
const;
241 static void decode(
const std::string& schemaString,
const std::vector<std::vector<uint8_t> >& encodedData, std::vector<GenericRecord>& data );
250 static void decode(
const std::string& schemaString,
const std::vector<uint8_t>& encodedData,
GenericRecord& data );
255 std::vector<boost::any> m_values;
257 GenericRecord(
const std::vector<std::pair<Type::Column::ColumnType, bool> >& columnTypes);
260 static void transpose(
const std::string& schemaString,
const std::vector<uint8_t>& encodedData, std::vector<GenericRecord>& data,
gpudb_type_ptr_t &dataTypePtr );
269 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)