GPUdb C++ API  Version 7.0.19.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  std::string getTypeName() const;
38  bool isNullable() const;
39  const std::vector<std::string>& getProperties() const;
40  bool hasProperty( std::string property ) const;
41 
46  bool isColumnCompatible(const Column &other, bool check_query_compatibility = false ) const;
47 
48  friend bool operator==(const Column &lhs, const Column &rhs); // overloading ==
49  friend std::ostream &operator << (std::ostream &os, const Column &column);
50  friend std::ostream &operator << (std::ostream &os, Column &column);
51 
52  private:
53  std::string m_name;
54  ColumnType m_type;
55  bool m_isNullable;
56  std::vector<std::string> m_properties; // kept sorted
57 
58  void initialize();
59  };
60 
62  static Type fromTable(const GPUdb& gpudb, const std::string& tableName);
64  static Type fromType(const GPUdb& gpudb, const std::string& typeId);
65 
66  Type(const std::vector<Column>& columns);
67  Type(const std::string& label, const std::vector<Column>& columns);
68  Type(const std::string& typeSchema);
69  Type(const std::string& label, const std::string& typeSchema, const std::map<std::string, std::vector<std::string> >& properties);
70  const std::string& getLabel() const;
71  const std::vector<Column>& getColumns() const;
72  const Column& getColumn(const size_t index) const;
73  const Column& getColumn(const std::string& name) const;
74  size_t getColumnCount() const;
75  size_t getColumnIndex(const std::string& name) const;
76  bool hasColumn(const std::string& name) const;
77  const ::avro::ValidSchema& getSchema() const;
78  std::string create(const GPUdb& gpudb) const;
79 
84  bool isTypeCompatible(const Type &other, bool check_query_compatibility = false ) const;
85 
86  friend std::ostream &operator << (std::ostream &os, Type &type);
87  friend std::ostream &operator << (std::ostream &os, const Type &type);
88 
89 
90  private:
91  struct TypeData
92  {
93  std::string label;
94  std::vector<Type::Column> columns;
95  std::map<std::string, size_t> columnMap;
96  ::avro::ValidSchema schema;
97  };
98 
99  // Using a shared pointer to store all relevant data so that there is only
100  // one instance of it across all copies of the same type
101  // Do NOT add any member outside of m_data.
102  boost::shared_ptr<TypeData> m_data;
103 
104  Type();
105  void initialize();
106  void createFromSchema(const std::string& typeSchema, const std::map<std::string, std::vector<std::string> >& properties);
107  void createSchema();
108  };
109 }
110 
111 #endif
bool isNullable() const
const std::vector< std::string > & getProperties() const
const std::string & getName() const
ColumnType getType() const
friend std::ostream & operator<<(std::ostream &os, Type &type)
static Type fromTable(const GPUdb &gpudb, const std::string &tableName)
Create a Type object from a GPUdb table.
size_t getColumnIndex(const std::string &name) 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 hasColumn(const std::string &name) const
std::string getTypeName() const
bool hasProperty(std::string property) const
const std::vector< Column > & getColumns() const
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...
const ::avro::ValidSchema & getSchema() const
static Type fromType(const GPUdb &gpudb, const std::string &typeId)
Create a Type object from a GPUdb type.
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...
std::string create(const GPUdb &gpudb) const
const std::string & getLabel() const
size_t getColumnCount() const
const Column & getColumn(const size_t index) const