-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvdb.cpp
60 lines (49 loc) · 1.7 KB
/
convdb.cpp
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
#include <rocksdb/db.h>
#include <cxxopts.hpp>
#include <indicators.hpp>
#include <iostream>
#include "export.hpp"
#include "rocksdb.hpp"
int main(int argc, char** argv) {
std::string inputPath;
std::string outputFile;
enum class OutFormat { sparsematrix, condensed };
OutFormat outformat = OutFormat::sparsematrix;
cxxopts::Options options("kconv",
"Convert a raw rocksdb output to various output format");
options.add_options()("i,input", "input db path",
cxxopts::value<std::string>(inputPath))(
"o,output", "output file path",
cxxopts::value<std::string>(outputFile)->default_value("kmap_out.csv"))(
"f,output-format",
"output format (sparsematrix, condensed). Default = sparsematrix",
cxxopts::value<std::string>()->default_value("sparsematrix"))("h,help",
"Print usage");
auto opt = options.parse(argc, argv);
if (opt.count("help")) {
std::cout << options.help() << std::endl;
exit(0);
}
if (opt["output-format"].as<std::string>() == "sparsematrix") {
outformat = OutFormat::sparsematrix;
} else if (opt["output-format"].as<std::string>() == "condensed") {
outformat = OutFormat::condensed;
} else {
std::cerr << "Invalid output format \"" << opt["output-format"].as<std::string>()
<< "\"; available: sparsematrix" << std::endl;
exit(1);
}
RocksDB rdb{};
rdb.opts.error_if_exists = false;
rdb.opts.create_if_missing = false;
rdb.openRO(inputPath);
switch (outformat) {
case OutFormat::condensed:
dbToCondensed(rdb, outputFile);
break;
default:
case OutFormat::sparsematrix:
dbToSparseMatrix(rdb, outputFile);
break;
}
}