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; } }
27 friend struct ::avro::codec_traits<GenericRecord>;
34 const ::avro::ValidSchema&
getSchema()
const;
36 template<
typename T> T&
value(
const size_t index)
38 T* o = boost::any_cast<T>(&m_values.at(index));
39 if (!o)
throw std::runtime_error(
"Error converting GenericRecord column " + boost::lexical_cast<std::string>(index) +
" to type " + boost::core::demangle(
typeid(T).name() ));
43 template<
typename T>
const T&
value(
const size_t index)
const 45 const T* o = boost::any_cast<T>(&m_values.at(index));
46 if (!o)
throw std::runtime_error(
"Error converting GenericRecord column " + boost::lexical_cast<std::string>(index) +
" to type " + boost::core::demangle(
typeid(T).name() ));
50 template<
typename T> T&
value(
const std::string& name)
53 if (!o)
throw std::runtime_error(
"Error converting GenericRecord column '" + name +
"' to type " + boost::core::demangle(
typeid(T).name() ));
57 template<
typename T>
const T&
value(
const std::string& name)
const 59 const T* o = boost::any_cast<T>(&m_values[m_type.
getColumnIndex(name)]);
60 if (!o)
throw std::runtime_error(
"Error converting GenericRecord column '" + name +
"' to type " + boost::core::demangle(
typeid(T).name() ));
64 std::vector<uint8_t>&
bytesValue(
const size_t index);
65 const std::vector<uint8_t>&
bytesValue(
const size_t index)
const;
66 std::vector<uint8_t>&
bytesValue(
const std::string& name);
67 const std::vector<uint8_t>&
bytesValue(
const std::string& name)
const;
70 const double&
doubleValue(
const size_t index)
const;
72 const double&
doubleValue(
const std::string& name)
const;
75 const float&
floatValue(
const size_t index)
const;
77 const float&
floatValue(
const std::string& name)
const;
79 int32_t&
intValue(
const size_t index);
80 const int32_t&
intValue(
const size_t index)
const;
81 int32_t&
intValue(
const std::string& name);
82 const int32_t&
intValue(
const std::string& name)
const;
85 const int64_t&
longValue(
const size_t index)
const;
86 int64_t&
longValue(
const std::string& name);
87 const int64_t&
longValue(
const std::string& name)
const;
90 const std::string&
stringValue(
const size_t index)
const;
92 const std::string&
stringValue(
const std::string& name)
const;
95 const boost::optional<std::vector<uint8_t> >&
nullableBytesValue(
const size_t index)
const;
97 const boost::optional<std::vector<uint8_t> >&
nullableBytesValue(
const std::string& name)
const;
112 const boost::optional<int32_t>&
nullableIntValue(
const std::string& name)
const;
117 const boost::optional<int64_t>&
nullableLongValue(
const std::string& name)
const;
124 bool isNull(
const size_t index)
const;
125 bool isNull(
const std::string& name)
const;
127 template<
typename T>
void getAsArray(
const size_t index, std::vector<T>& result)
const;
128 template<
typename T>
void getAsArray(
const std::string& name, std::vector<T>& result)
const;
129 template<
typename T> std::vector<T>
getAsArray(
const size_t index)
const;
130 template<
typename T> std::vector<T>
getAsArray(
const std::string& name)
const;
132 void getAsBytes(
const size_t index, std::vector<uint8_t>& result)
const;
133 void getAsBytes(
const std::string& name, std::vector<uint8_t>& result)
const;
134 std::vector<uint8_t>
getAsBytes(
const size_t index)
const;
135 std::vector<uint8_t>
getAsBytes(
const std::string& name)
const;
137 void getAsDouble(
const size_t index,
double& result)
const;
138 void getAsDouble(
const std::string& name,
double& result)
const;
142 void getAsFloat(
const size_t index,
float& result)
const;
143 void getAsFloat(
const std::string& name,
float& result)
const;
145 float getAsFloat(
const std::string& name)
const;
147 void getAsInt(
const size_t index, int32_t& result)
const;
148 void getAsInt(
const std::string& name, int32_t& result)
const;
149 int32_t
getAsInt(
const size_t index)
const;
150 int32_t
getAsInt(
const std::string& name)
const;
152 void getAsLong(
const size_t index, int64_t& result)
const;
153 void getAsLong(
const std::string& name, int64_t& result)
const;
154 int64_t
getAsLong(
const size_t index)
const;
155 int64_t
getAsLong(
const std::string& name)
const;
157 void getAsString(
const size_t index, std::string& result)
const;
158 void getAsString(
const std::string& name, std::string& result)
const;
160 std::string
getAsString(
const std::string& name)
const;
162 void getAsVector(
const size_t index, std::vector<float>& result)
const;
163 void getAsVector(
const std::string& name, std::vector<float>& result)
const;
164 std::vector<float>
getAsVector(
const size_t index)
const;
165 std::vector<float>
getAsVector(
const std::string& name)
const;
167 void getAsNullableBytes(
const size_t index, boost::optional<std::vector<uint8_t> >& result)
const;
168 void getAsNullableBytes(
const std::string& name, boost::optional<std::vector<uint8_t> >& result)
const;
170 boost::optional<std::vector<uint8_t> >
getAsNullableBytes(
const std::string& name)
const;
178 void getAsNullableFloat(
const std::string& name, boost::optional<float>& result)
const;
182 void getAsNullableInt(
const size_t index, boost::optional<int32_t>& result)
const;
183 void getAsNullableInt(
const std::string& name, boost::optional<int32_t>& result)
const;
187 void getAsNullableLong(
const size_t index, boost::optional<int64_t>& result)
const;
188 void getAsNullableLong(
const std::string& name, boost::optional<int64_t>& result)
const;
193 void getAsNullableString(
const std::string& name, boost::optional<std::string>& result)
const;
197 void setNull(
const size_t index);
198 void setNull(
const std::string& name);
200 template<
typename T>
void setAsArray(
const size_t index,
const std::vector<T>& newValue);
201 template<
typename T>
void setAsArray(
const std::string& name,
const std::vector<T>& newValue);
203 void setAsBytes(
const size_t index,
const std::vector<uint8_t>& newValue);
204 void setAsBytes(
const std::string& name,
const std::vector<uint8_t>& newValue);
206 void setAsDouble(
const size_t index,
const double& newValue);
207 void setAsDouble(
const std::string& name,
const double& newValue);
209 void setAsFloat(
const size_t index,
const float& newValue);
210 void setAsFloat(
const std::string& name,
const float& newValue);
212 void setAsInt(
const size_t index,
const int32_t& newValue);
213 void setAsInt(
const std::string& name,
const int32_t& newValue);
215 void setAsLong(
const size_t index,
const int64_t& newValue);
216 void setAsLong(
const std::string& name,
const int64_t& newValue);
218 void setAsString(
const size_t index,
const std::string& newValue);
219 void setAsString(
const std::string& name,
const std::string& newValue);
221 void setAsVector(
const size_t index,
const std::vector<float>& newValue);
222 void setAsVector(
const std::string& name,
const std::vector<float>& newValue);
224 void setAsNullableBytes(
const size_t index,
const boost::optional<std::vector<uint8_t> >& newValue);
225 void setAsNullableBytes(
const std::string& name,
const boost::optional<std::vector<uint8_t> >& newValue);
228 void setAsNullableDouble(
const std::string& name,
const boost::optional<double>& newValue);
231 void setAsNullableFloat(
const std::string& name,
const boost::optional<float>& newValue);
233 void setAsNullableInt(
const size_t index,
const boost::optional<int32_t>& newValue);
234 void setAsNullableInt(
const std::string& name,
const boost::optional<int32_t>& newValue);
236 void setAsNullableLong(
const size_t index,
const boost::optional<int64_t>& newValue);
237 void setAsNullableLong(
const std::string& name,
const boost::optional<int64_t>& newValue);
239 void setAsNullableString(
const size_t index,
const boost::optional<std::string>& newValue);
240 void setAsNullableString(
const std::string& name,
const boost::optional<std::string>& newValue);
242 void toString(
const size_t index, std::string& result)
const;
243 void toString(
const std::string& name, std::string& result)
const;
244 std::string
toString(
const size_t index)
const;
245 std::string
toString(
const std::string& name)
const;
258 static void decode(
const std::string& schemaString,
const std::vector<std::vector<uint8_t> >& encodedData, std::vector<GenericRecord>& data );
267 static void decode(
const std::string& schemaString,
const std::vector<uint8_t>& encodedData,
GenericRecord& data );
272 std::vector<boost::any> m_values;
274 GenericRecord(
const std::vector<std::pair<Type::Column::ColumnType, bool> >& columnTypes);
277 static void transpose(
const std::string& schemaString,
const std::vector<uint8_t>& encodedData, std::vector<GenericRecord>& data,
gpudb_type_ptr_t &dataTypePtr );
286 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
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)
void getAsArray(const size_t index, std::vector< T > &result) const
std::string & stringValue(const size_t index)
void getAsNullableBytes(const size_t index, boost::optional< std::vector< uint8_t > > &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 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)
void setAsVector(const size_t index, const std::vector< float > &newValue)
friend std::ostream & operator<<(std::ostream &os, GenericRecord &gr)
std::string JsonStringFromVector(const std::vector< T > &vector)
void setAsArray(const size_t index, const std::vector< T > &newValue)
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 getAsVector(const size_t index, std::vector< float > &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 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)