GPUdb C++ API  Version 7.2.2.4
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 // The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.
7 #define BOOST_BIND_GLOBAL_PLACEHOLDERS
8 #include <avro/Schema.hh>
9 
10 namespace gpudb
11 {
12  class GPUdb;
13 
14  /*
15  * This class is thread safe and immutable.
16  */
17  class Type
18  {
19  friend class GenericRecord;
20 
21  public:
22  class Column
23  {
24  public:
26  {
27  BYTES = ::avro::AVRO_BYTES,
28  DOUBLE = ::avro::AVRO_DOUBLE,
29  FLOAT = ::avro::AVRO_FLOAT,
30  INT = ::avro::AVRO_INT,
31  LONG = ::avro::AVRO_LONG,
32  STRING = ::avro::AVRO_STRING
33  };
34 
35  Column(const std::string& name, const ColumnType type, const std::string& property1 = "", const std::string& property2 = "", const std::string& property3 = "");
36  Column(const std::string& name, const ColumnType type, const std::vector<std::string>& properties);
37  const std::string& getName() const;
38  ColumnType getType() const;
39  std::string getTypeName() const;
40  bool isNullable() const;
41  bool isArray() const;
42  std::string getArrayType() const;
43  const std::vector<std::string>& getProperties() const;
44  bool hasProperty( std::string property ) const;
45  bool isVector() const;
46  int getVectorDimensions() const;
47 
52  bool isColumnCompatible(const Column &other, bool check_query_compatibility = false ) const;
53 
54  friend bool operator==(const Column &lhs, const Column &rhs); // overloading ==
55  friend std::ostream &operator << (std::ostream &os, const Column &column);
56  friend std::ostream &operator << (std::ostream &os, Column &column);
57 
58  private:
59  std::string m_name;
60  ColumnType m_type;
61  bool m_isNullable;
62  std::vector<std::string> m_properties; // kept sorted
63 
64  void initialize();
65  };
66 
68  static Type fromTable(const GPUdb& gpudb, const std::string& tableName);
70  static Type fromType(const GPUdb& gpudb, const std::string& typeId);
71 
72  Type(const std::vector<Column>& columns);
73  Type(const std::string& label, const std::vector<Column>& columns);
74  Type(const std::string& typeSchema);
75  Type(const std::string& label, const std::string& typeSchema, const std::map<std::string, std::vector<std::string> >& properties);
76  const std::string& getLabel() const;
77  const std::vector<Column>& getColumns() const;
78  const Column& getColumn(const size_t index) const;
79  const Column& getColumn(const std::string& name) const;
80  size_t getColumnCount() const;
81  size_t getColumnIndex(const std::string& name) const;
82  bool hasColumn(const std::string& name) const;
83  const ::avro::ValidSchema& getSchema() const;
84  std::string create(const GPUdb& gpudb) const;
85 
90  bool isTypeCompatible(const Type &other, bool check_query_compatibility = false ) const;
91 
92  friend std::ostream &operator << (std::ostream &os, Type &type);
93  friend std::ostream &operator << (std::ostream &os, const Type &type);
94 
95 
96  private:
97  struct TypeData
98  {
99  std::string label;
100  std::vector<Type::Column> columns;
101  std::map<std::string, size_t> columnMap;
102  ::avro::ValidSchema schema;
103  };
104 
105  // Using a shared pointer to store all relevant data so that there is only
106  // one instance of it across all copies of the same type
107  // Do NOT add any member outside of m_data.
108  boost::shared_ptr<TypeData> m_data;
109 
110  Type();
111  void initialize();
112  void createFromSchema(const std::string& typeSchema, const std::map<std::string, std::vector<std::string> >& properties);
113  void createSchema();
114  };
115 }
116 
117 #endif
size_t getColumnCount() const
bool isTypeCompatible(const Type &other, bool check_query_compatibility=false) const
Check if the given type's columns' data types are compatible (checks primitive types and type-related...
const std::string & getName() 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.
const ::avro::ValidSchema & getSchema() const
friend std::ostream & operator<<(std::ostream &os, const Column &column)
friend bool operator==(const Column &lhs, const Column &rhs)
bool isArray() const
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
std::string getTypeName() const
bool hasProperty(std::string property) const
bool isVector() const
const Column & getColumn(const size_t index) const
static Type fromType(const GPUdb &gpudb, const std::string &typeId)
Create a Type object from a GPUdb type.
int getVectorDimensions() const
const std::vector< std::string > & getProperties() const
const std::string & getLabel() const
std::string getArrayType() 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