GPUdb C++ API  Version 6.1.0.0
Type.hpp
Go to the documentation of this file.
1 #ifndef __GPUDB__TYPE_HPP__
2 #define __GPUDB__TYPE_HPP__
3 
4 #include "ColumnProperties.h"
5 
6 #include <avro/Schema.hh>
7 
8 namespace gpudb
9 {
10  class GPUdb;
11 
12  /*
13  * This class is thread safe and immutable.
14  */
15  class Type
16  {
17  friend class GenericRecord;
18 
19  public:
20  class Column
21  {
22  public:
24  {
25  BYTES = ::avro::AVRO_BYTES,
26  DOUBLE = ::avro::AVRO_DOUBLE,
27  FLOAT = ::avro::AVRO_FLOAT,
28  INT = ::avro::AVRO_INT,
29  LONG = ::avro::AVRO_LONG,
30  STRING = ::avro::AVRO_STRING
31  };
32 
33  Column(const std::string& name, const ColumnType type, const std::string& property1 = "", const std::string& property2 = "", const std::string& property3 = "");
34  Column(const std::string& name, const ColumnType type, const std::vector<std::string>& properties);
35  const std::string& getName() const;
36  ColumnType getType() const;
37  bool isNullable() const;
38  const std::vector<std::string>& getProperties() const;
39  bool hasProperty( std::string property ) const;
40 
45  bool isColumnCompatible(const Column &other, bool check_query_compatibility = false ) const;
46 
47  friend bool operator==(const Column &lhs, const Column &rhs); // overloading ==
48  friend std::ostream &operator << (std::ostream &os, const Column &column);
49  friend std::ostream &operator << (std::ostream &os, Column &column);
50 
51  private:
52  std::string m_name;
53  ColumnType m_type;
54  bool m_isNullable;
55  std::vector<std::string> m_properties; // kept sorted
56 
57  void initialize();
58  };
59 
60  static Type fromTable(const GPUdb& gpudb, const std::string& tableName);
61  static Type fromType(const GPUdb& gpudb, const std::string& typeId);
62 
63  Type(const std::vector<Column>& columns);
64  Type(const std::string& label, const std::vector<Column>& columns);
65  Type(const std::string& typeSchema);
66  Type(const std::string& label, const std::string& typeSchema, const std::map<std::string, std::vector<std::string> >& properties);
67  const std::string& getLabel() const;
68  const std::vector<Column>& getColumns() const;
69  const Column& getColumn(const size_t index) const;
70  const Column& getColumn(const std::string& name) const;
71  size_t getColumnCount() const;
72  size_t getColumnIndex(const std::string& name) const;
73  bool hasColumn(const std::string& name) const;
74  const ::avro::ValidSchema& getSchema() const;
75  std::string create(const GPUdb& gpudb) const;
76 
81  bool isTypeCompatible(const Type &other, bool check_query_compatibility = false ) const;
82 
83  private:
84  struct TypeData
85  {
86  std::string label;
87  std::vector<Type::Column> columns;
88  std::map<std::string, size_t> columnMap;
89  ::avro::ValidSchema schema;
90  };
91 
92  // Using a shared pointer to store all relevant data so that there is only
93  // one instance of it across all copies of the same type
94  // Do NOT add any member outside of m_data.
95  boost::shared_ptr<TypeData> m_data;
96 
97  Type();
98  void initialize();
99  void createFromSchema(const std::string& typeSchema, const std::map<std::string, std::vector<std::string> >& properties);
100  void createSchema();
101  };
102 }
103 
104 #endif
size_t getColumnCount() const
bool isTypeCompatible(const Type &other, bool check_query_compatibility=false) const
Check if the given type&#39;s columns&#39; data types are compatible (checks primitive types and type-related...
const std::string & getName() const
static Type fromTable(const GPUdb &gpudb, const std::string &tableName)
const ::avro::ValidSchema & getSchema() const
friend std::ostream & operator<<(std::ostream &os, const Column &column)
friend bool operator==(const Column &lhs, const Column &rhs)
Column(const std::string &name, const ColumnType type, const std::string &property1="", const std::string &property2="", const std::string &property3="")
bool isColumnCompatible(const Column &other, bool check_query_compatibility=false) const
Check if the given column is compatible with this column (checks name, primitive types and type-relat...
ColumnType getType() const
bool hasProperty(std::string property) const
const Column & getColumn(const size_t index) const
static Type fromType(const GPUdb &gpudb, const std::string &typeId)
const std::vector< std::string > & getProperties() const
const std::string & getLabel() const
std::string create(const GPUdb &gpudb) const
size_t getColumnIndex(const std::string &name) const
bool hasColumn(const std::string &name) const
const std::vector< Column > & getColumns() const
bool isNullable() const