-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathmain.cpp
More file actions
166 lines (154 loc) · 5.55 KB
/
main.cpp
File metadata and controls
166 lines (154 loc) · 5.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
* Copyright 2024 PixelsDB.
*
* This file is part of Pixels.
*
* Pixels is free software: you can redistribute it and/or modify
* it under the terms of the Affero GNU General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* Pixels is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Affero GNU General Public License for more details.
*
* You should have received a copy of the Affero GNU General Public
* License along with Pixels. If not, see
* <https://www.gnu.org/licenses/>.
*/
/*
* @author gengdy
* @create 2024-11-16
*/
#include <iostream>
#include <sstream>
#include <string>
#include <boost/algorithm/string.hpp>
#include <boost/program_options.hpp>
#include <executor/LoadExecutor.h>
namespace bpo = boost::program_options;
int main()
{
std::string inputStr;
while (true)
{
std::cout << "pixels> ";
if (!std::getline(std::cin, inputStr))
{
// in case of input from a file, exit at EOF
std::cout << "Bye." << std::endl;
break;
}
boost::trim(inputStr);
if (inputStr.empty() || inputStr == ";")
{
continue;
}
if (inputStr.back() == ';')
{
inputStr.pop_back();
}
// process exit command
std::string lowerInputStr = boost::to_lower_copy(inputStr);
if (lowerInputStr == "exit" || lowerInputStr == "quit" || lowerInputStr == "-q")
{
std::cout << "Bye." << std::endl;
break;
}
// process help command
if (lowerInputStr == "help" || lowerInputStr == "-h")
{
std::cout << "Supported commands:\n" <<
"LOAD\n" <<
"COMPACT\n" <<
"IMPORT\n" <<
"STAT\n" <<
"QUERY\n" <<
"COPY\n" <<
"FILE_META\n";
std::cout << "{command} -h to show the usage of a command.\nexit / quit / -q to exit.\n";
continue;
}
// Split input into tokens as char* array
std::istringstream iss(inputStr);
std::vector <std::string> token_strings{std::istream_iterator < std::string > {iss},
std::istream_iterator < std::string > {}};
std::vector<char *> argv;
for (const auto &str: token_strings)
{
argv.push_back(strdup(str.c_str())); // Duplicate strings as char*
}
if (argv.empty())
{
continue;
}
std::string command = argv[0];
boost::to_upper(command);
if (command == "LOAD")
{
bpo::options_description desc("Pixels ETL LOAD");
desc.add_options()
("help,h", "show this help message and exit")
("origin,o", bpo::value<std::string>()->required(), "specify the path of original data files")
("target,t", bpo::value<std::string>()->required(), "specify the path of target data files")
("schema,s", bpo::value<std::string>()->required(), "specify the schema of pixels")
("row_num,n", bpo::value<int>()->required(), "specify the max number of rows to write in a file")
("row_regex,r", bpo::value<std::string>()->required(),
"specify the split regex of each row in a file")
("encoding_level,e", bpo::value<int>()->default_value(2),
"specify the encoding level for data loading")
("nulls_padding,p", bpo::value<bool>()->default_value(false),
"specify whether nulls padding is enabled")
("concurrency,c", bpo::value<int>()->default_value(1),
"specify the number of threads for data loading");
bpo::variables_map vm;
try
{
bpo::store(bpo::parse_command_line(argv.size(), argv.data(), desc), vm);
if (vm.count("help"))
{
std::cout << desc << std::endl;
continue;
}
bpo::notify(vm);
}
catch (const bpo::error &e)
{
std::cerr << "Error parsing options: " << e.what() << "\n";
}
std::unique_ptr<LoadExecutor> loadExecutor = std::make_unique<LoadExecutor>();
loadExecutor->execute(vm, command);
}
else if (command == "QUERY")
{
std::cout << "Not implemented yet." << std::endl;
}
else if (command == "COPY")
{
std::cout << "Not implemented yet." << std::endl;
}
else if (command == "COMPACT")
{
std::cout << "Not implemented yet." << std::endl;
}
else if (command == "STAT")
{
std::cout << "Not implemented yet." << std::endl;
}
else if (command == "IMPORT")
{
std::cout << "Not implemented yet." << std::endl;
}
else if (command == "FILE_META")
{
std::cout << "Not implemented yet." << std::endl;
}
else
{
std::cout << "Command " << command << " not found" << std::endl;
}
for (char* p : argv) free(p);
} // end of while loop
return 0;
}