GPUdb C++ API  Version 5.2.0.0
Type.hpp
Go to the documentation of this file.
1 #ifndef __GPUDB__TYPE_HPP__
2 #define __GPUDB__TYPE_HPP__
3 
4 #include <avro/Schema.hh>
5 
6 namespace gpudb
7 {
8  class GPUdb;
9 
10  class Type
11  {
12  friend class GenericRecord;
13 
14  public:
15  class Column
16  {
17  public:
19  {
20  BYTES = ::avro::AVRO_BYTES,
21  DOUBLE = ::avro::AVRO_DOUBLE,
22  FLOAT = ::avro::AVRO_FLOAT,
23  INT = ::avro::AVRO_INT,
24  LONG = ::avro::AVRO_LONG,
25  STRING = ::avro::AVRO_STRING
26  };
27 
28  Column(const std::string& name, const ColumnType type);
29  Column(const std::string& name, const ColumnType type, const std::vector<std::string>& properties);
30  const std::string& getName() const;
31  ColumnType getType() const;
32  bool isNullable() const;
33  const std::vector<std::string>& getProperties() const;
34 
35  private:
36  std::string m_name;
37  ColumnType m_type;
38  bool m_isNullable;
39  std::vector<std::string> m_properties;
40 
41  void initialize();
42  };
43 
44  static Type fromTable(const GPUdb& gpudb, const std::string& tableName);
45  static Type fromType(const GPUdb& gpudb, const std::string& typeId);
46 
47  Type(const std::vector<Column>& columns);
48  Type(const std::string& label, const std::vector<Column>& columns);
49  Type(const std::string& typeSchema);
50  Type(const std::string& label, const std::string& typeSchema, const std::map<std::string, std::vector<std::string> >& properties);
51  const std::string& getLabel() const;
52  const std::vector<Column>& getColumns() const;
53  const Column& getColumn(const size_t index) const;
54  const Column& getColumn(const std::string& name) const;
55  size_t getColumnCount() const;
56  size_t getColumnIndex(const std::string& name) const;
57  bool hasColumn(const std::string& name) const;
58  const ::avro::ValidSchema& getSchema() const;
59  std::string create(const GPUdb& gpudb) const;
60 
61  private:
62  struct TypeData
63  {
64  std::string label;
65  std::vector<Type::Column> columns;
66  std::map<std::string, size_t> columnMap;
67  ::avro::ValidSchema schema;
68  };
69 
70  boost::shared_ptr<TypeData> m_data;
71 
72  Type();
73  void initialize();
74  void createFromSchema(const std::string& typeSchema, const std::map<std::string, std::vector<std::string> >& properties);
75  void createSchema();
76  };
77 }
78 
79 #endif
bool isNullable() const
const std::vector< std::string > & getProperties() const
const std::string & getName() const
ColumnType getType() const
static Type fromTable(const GPUdb &gpudb, const std::string &tableName)
size_t getColumnIndex(const std::string &name) const
bool hasColumn(const std::string &name) const
const std::vector< Column > & getColumns() const
Column(const std::string &name, const ColumnType type)
const ::avro::ValidSchema & getSchema() const
static Type fromType(const GPUdb &gpudb, const std::string &typeId)
std::string create(const GPUdb &gpudb) const
const std::string & getLabel() const
size_t getColumnCount() const
const Column & getColumn(const size_t index) const