Column Store
StoreInitializer.h
Go to the documentation of this file.
1 #pragma once
2 #include <fstream>
3 #include <iostream>
4 #include <nlohmann/json.hpp>
5 
7 
8 #include <experimental/filesystem>
9 
10 #ifdef __cpp_lib_filesystem
11 namespace fs = std::filesystem;
12 #elif __cpp_lib_experimental_filesystem
13 namespace fs = std::experimental::filesystem;
14 #else
15 #error "no filesystem support ='("
16 #endif
17 
18 using nlohmann::json;
19 
20 namespace ColumnStore {
21 
22 fs::path getProjectionPath(std::string column_store_path,
23  std::string projection_name) {
24  return fs::absolute(fs::path(column_store_path) / "projections" /
25  (projection_name + ".projection"));
26 }
27 
28 fs::path getMetaDataPath(std::string column_store_path) {
29  return fs::absolute(fs::path(column_store_path) / "metadata.json");
30 }
31 
32 fs::path getSchemaPath(std::string column_store_path) {
33  return fs::absolute(fs::path(column_store_path) / "schema.xml");
34 }
35 
36 fs::path getJoinIndexPath(std::string column_store_path,
37  std::string source_projection_name,
38  Parser::join_index join_index) {
39  std::string fileName =
40  source_projection_name + "_" + join_index.projection + ".index";
41  auto path = fs::path(column_store_path) / "joins" / fileName;
42  return fs::absolute(path);
43 }
44 
45 void createFile(fs::path path) {
46  fs::create_directories(path.parent_path());
47 
48  std::ofstream ofs(path);
49  ofs.close();
50 }
51 
52 class Initializer {
54  Parser::Projection projection) {
55  std::string name = projection.get_projection_name();
56  fs::path path = getProjectionPath(column_store_path, name);
57 
58  createFile(path);
59 
60  for (auto &index : projection.get_join_indexes()) {
61  fs::path path = getJoinIndexPath(column_store_path, name, index);
62  createFile(path);
63  }
64  }
65 
67  std::string name = projection.get_projection_name();
68 
69  json projection_metadata = {
70  {"name", name},
71  {"file", getProjectionPath(column_store_path, name)},
72  {"tuples_move_count", 0},
73  {"joins", json::object()},
74  };
75 
76  for (auto &index : projection.get_join_indexes()) {
77  projection_metadata["joins"][index.projection] =
78  getJoinIndexPath(column_store_path, name, index);
79  }
80  return projection_metadata;
81  }
82 
83  json metadata;
84  std::string column_store_path;
85 
86  public:
89 
90  void saveMetadata() {
91  // Print MetaData
92  std::cout << metadata.dump(4) << std::endl;
93 
94  // Store Metadata
95  std::ofstream o(getMetaDataPath(column_store_path));
96  o << metadata.dump(4) << std::endl;
97  o.close();
98  }
99 
101  metadata["projections"] = json::object();
102 
103  for (auto &projection : schema_metadata.get_projections()) {
105  }
106 
107  for (auto &projection : schema_metadata.get_projections()) {
108  std::string name = projection.get_projection_name();
109 
110  metadata["projections"][name] =
111  generateMetadataProjection(projection);
112  }
113  }
114 
115  void configureSourceDB(std::string db_name, std::string db_user,
116  std::string db_password) {
117  metadata["source_db_config"] = {{"db_name", db_name},
118  {"db_user", db_user},
119  {"db_password", db_password}};
120  }
121 
122  void configureSchema(std::string schame_path) {
123  fs::path path = getSchemaPath(column_store_path);
124  fs::copy_file(schame_path, path, fs::copy_options::overwrite_existing);
125  metadata["schema_path"] = path;
126  }
127 };
128 } // namespace ColumnStore
ColumnStore::createFile
void createFile(fs::path path)
Definition: StoreInitializer.h:45
SchemaMetaData.h
Parser::SchemaMetaData
Definition: SchemaMetaData.h:14
Parser::Projection::get_join_indexes
vector< join_index > get_join_indexes()
Definition: Projection.h:70
ColumnStore
Definition: ColStoreDataGenerator.h:22
main
int main(int ac, char *av[])
Definition: Driver.cpp:61
ColumnStore::Initializer::configureSchema
void configureSchema(std::string schame_path)
Definition: StoreInitializer.h:122
ColumnStore::Initializer::saveMetadata
void saveMetadata()
Definition: StoreInitializer.h:90
Parser
Definition: Column.h:6
Parser::SchemaLoader
Definition: SchemaLoader.h:13
ColumnStore::Initializer::generateMetadataProjection
json generateMetadataProjection(Parser::Projection &projection)
Definition: StoreInitializer.h:66
ColumnStore::Initializer::_createProjection
void _createProjection(std::string column_store_path, Parser::Projection projection)
Definition: StoreInitializer.h:53
ColumnStore::Initializer::configureSourceDB
void configureSourceDB(std::string db_name, std::string db_user, std::string db_password)
Definition: StoreInitializer.h:115
Parser::Projection
Definition: Projection.h:44
ColumnStore::Initializer::createProjections
void createProjections(Parser::SchemaMetaData schema_metadata)
Definition: StoreInitializer.h:100
Parser::Projection::get_projection_name
std::string get_projection_name()
Definition: Projection.h:65
StoreInitializer.h
ColumnStore::getMetaDataPath
fs::path getMetaDataPath(std::string column_store_path)
Definition: StoreInitializer.h:28
SchemaLoader.h
ColumnStore::Initializer::column_store_path
std::string column_store_path
Definition: StoreInitializer.h:84
Parser::SchemaMetaData::get_projections
vector< Projection > & get_projections()
Definition: SchemaMetaData.h:31
Parser::join_index
Definition: JoinIndex.h:6
ColumnStore::getSchemaPath
fs::path getSchemaPath(std::string column_store_path)
Definition: StoreInitializer.h:32
ColumnStore::getProjectionPath
fs::path getProjectionPath(std::string column_store_path, std::string projection_name)
Definition: StoreInitializer.h:22
initConfig
void initConfig(int ac, char *av[])
Definition: Driver.cpp:13
ColumnStore::Initializer::Initializer
Initializer(std::string column_store_path)
Definition: StoreInitializer.h:87
Parser::SchemaExtractor
Definition: SchemaExtractor.h:14
Parser::DataLoader
Definition: DataLoader.h:9
ColumnStore::Initializer
Definition: StoreInitializer.h:52
config
po::variables_map config
Definition: Driver.cpp:11
DataLoader.h
ColumnStore::Initializer::metadata
json metadata
Definition: StoreInitializer.h:83
Parser::join_index::projection
std::string projection
Definition: JoinIndex.h:8
ColumnStore::getJoinIndexPath
fs::path getJoinIndexPath(std::string column_store_path, std::string source_projection_name, Parser::join_index join_index)
Definition: StoreInitializer.h:36