Column Store
Projection.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <unordered_map>
5 #include <vector>
6 
7 #include "Column.h"
8 #include "ForeignKey.h"
9 #include "JoinIndex.h"
10 #include "interfaces/DataRecord.h"
11 
12 namespace Parser {
13 using std::exception;
14 using std::runtime_error;
15 using std::string;
16 using std::unordered_map;
17 using std::vector;
18 class ProjectionNotFoundException : public exception {
19  std::string msg;
20 
21  public:
22  ProjectionNotFoundException(std::string& p_name)
23  : msg("Projection " + p_name + " not found") {}
24  virtual const char* what() const throw() { return msg.c_str(); }
25 };
26 
28  std::string name;
29  std::string table;
30  std::string column_name;
31  std::string encoding;
33  int index;
34 
35  operator Parser::DataType() { return data_type; }
36  operator ColumnStore::DataType() { return data_type; }
37  operator int() { return data_type; }
38  operator Parser::Column() { return Parser::Column(name, data_type, index); }
39  operator ColumnStore::Column() {
41  }
42 };
43 
44 class Projection {
45  std::string projection_name;
46  std::string sort_key;
47  vector<projection_column> columns;
48  unordered_map<string, int> column_map;
49  std::string base_table;
50  vector<foreign_key> join_tables;
51  vector<join_index> join_indexes;
52 
53  public:
54  void set_projection_name(std::string projection_n) {
55  projection_name = projection_n;
56  }
57  void set_base_table(std::string base_tab) { base_table = base_tab; }
58  void set_sort_key(std::string sk) { sort_key = sk; }
59  void add_column(std::string name, std::string table,
60  std::string column_name, std::string encoding,
61  DataType data_type);
62  void add_join_table(std::string from, std::string table, std::string to);
63  void add_join_index(std::string from, std::string other_projection,
64  std::string to);
65  std::string get_projection_name() { return projection_name; }
66  std::string get_base_table() { return base_table; }
67  std::string get_sort_key() { return sort_key; }
68  vector<foreign_key> get_join_tables() { return join_tables; }
69  vector<projection_column> get_columns() { return columns; }
70  vector<join_index> get_join_indexes() { return join_indexes; }
72  if (i >= int(columns.size())) {
73  throw runtime_error("Index out of Bounds in Projection:" +
75  }
76  return columns[i];
77  }
78  projection_column& get_column(std::string name) { return (*this)[name]; }
79  projection_column& operator[](std::string name) {
80  if (column_map.find(name) == column_map.end()) {
81  throw runtime_error("Projection " + projection_name +
82  " does not have column " + name);
83  }
84  return columns[column_map[name]];
85  }
86 
87  std::vector<Parser::Column> get_metadata_columns() {
88  std::vector<Parser::Column> result;
89  result.reserve(columns.size());
90  for (auto& c : columns) result.push_back(c);
91 
92  return result;
93  }
94 
96  std::vector<ColumnStore::Column> result;
97  result.reserve(columns.size());
98  for (auto& c : columns) result.push_back(c);
99 
100  return new ColumnStore::DataRecordMetadata(result);
101  }
102 };
103 } // namespace Parser
Parser::Projection::get_column
projection_column & get_column(std::string name)
Definition: Projection.h:78
Parser::projection_column::data_type
DataType data_type
Definition: Projection.h:32
ForeignKey.h
Parser::Projection::get_join_indexes
vector< join_index > get_join_indexes()
Definition: Projection.h:70
ColumnStore::DataType
DataType
Different datatypes supported by this project.
Definition: Column.h:16
Parser::Projection::operator[]
projection_column & operator[](int i)
Definition: Projection.h:71
ColumnStore::DataRecordMetadata
Stores metadata information of the data record.
Definition: DataRecord.h:88
Parser::Projection::base_table
std::string base_table
Definition: Projection.h:49
Parser::Projection::sort_key
std::string sort_key
Definition: Projection.h:46
Parser
Definition: Column.h:6
Parser::Projection::get_sort_key
std::string get_sort_key()
Definition: Projection.h:67
ColumnStore::Column
Struct which maintains metadata of a single column.
Definition: Column.h:22
Parser::Projection::add_join_table
void add_join_table(std::string from, std::string table, std::string to)
Definition: Projection.cpp:11
Parser::Projection::projection_name
std::string projection_name
Definition: Projection.h:45
Parser::Projection::columns
vector< projection_column > columns
Definition: Projection.h:47
Parser::Projection::set_projection_name
void set_projection_name(std::string projection_n)
Definition: Projection.h:54
Parser::DataType
Definition: Column.h:7
Parser::Projection
Definition: Projection.h:44
Parser::projection_column::column_name
std::string column_name
Definition: Projection.h:30
Parser::ProjectionNotFoundException::ProjectionNotFoundException
ProjectionNotFoundException(std::string &p_name)
Definition: Projection.h:22
Parser::Projection::get_columns
vector< projection_column > get_columns()
Definition: Projection.h:69
Parser::Projection::column_map
unordered_map< string, int > column_map
Definition: Projection.h:48
Parser::Projection::set_sort_key
void set_sort_key(std::string sk)
Definition: Projection.h:58
Parser::Projection::get_projection_name
std::string get_projection_name()
Definition: Projection.h:65
DataRecord.h
Data storage structures.
Parser::ProjectionNotFoundException
Definition: Projection.h:18
Parser::projection_column::encoding
std::string encoding
Definition: Projection.h:31
Parser::Projection::get_metadata
ColumnStore::DataRecordMetadata * get_metadata()
Definition: Projection.h:95
Parser::Projection::get_metadata_columns
std::vector< Parser::Column > get_metadata_columns()
Definition: Projection.h:87
Parser::Projection::set_base_table
void set_base_table(std::string base_tab)
Definition: Projection.h:57
Parser::Projection::operator[]
projection_column & operator[](std::string name)
Definition: Projection.h:79
JoinIndex.h
Parser::projection_column::table
std::string table
Definition: Projection.h:29
Column.h
Parser::Projection::get_base_table
std::string get_base_table()
Definition: Projection.h:66
Parser::projection_column
Definition: Projection.h:27
Parser::ProjectionNotFoundException::what
virtual const char * what() const
Definition: Projection.h:24
Parser::join_index
Definition: JoinIndex.h:6
Parser::Projection::add_column
void add_column(std::string name, std::string table, std::string column_name, std::string encoding, DataType data_type)
Definition: Projection.cpp:5
Parser::Projection::join_tables
vector< foreign_key > join_tables
Definition: Projection.h:50
Parser::projection_column::index
int index
Definition: Projection.h:33
Parser::Projection::join_indexes
vector< join_index > join_indexes
Definition: Projection.h:51
Parser::foreign_key
Definition: ForeignKey.h:6
Parser::Column
Definition: Column.h:38
Parser::Projection::get_join_tables
vector< foreign_key > get_join_tables()
Definition: Projection.h:68
Projection.h
Parser::Projection::add_join_index
void add_join_index(std::string from, std::string other_projection, std::string to)
Definition: Projection.cpp:16
Parser::DataType::size
int size
Definition: Column.h:9
Parser::ProjectionNotFoundException::msg
std::string msg
Definition: Projection.h:19
Parser::projection_column::name
std::string name
Definition: Projection.h:28