1 | #include <chrono> |
2 | #include <cstdio> |
3 | #include <stdlib.h> /* atoi */ |
4 | |
5 | #include "duckdb.hpp" |
6 | #include "dbgen.hpp" |
7 | |
8 | #include "duckdb/common/string_util.hpp" |
9 | |
10 | using namespace std; |
11 | using namespace duckdb; |
12 | |
13 | void print_help() { |
14 | fprintf(stderr, "🦆 Usage: duckdb_dbgen\n" ); |
15 | fprintf(stderr, " --database=[file] use given database file\n" ); |
16 | fprintf(stderr, " --scale_factor=[sf] TPCH scale factor (default: 1)\n" ); |
17 | } |
18 | |
19 | int main(int argc, char **argv) { |
20 | DBConfig config; |
21 | string dbfile; |
22 | double scale_factor = 1; |
23 | |
24 | // parse config |
25 | for (int arg_index = 1; arg_index < argc; ++arg_index) { |
26 | string arg = argv[arg_index]; |
27 | if (arg == "--help" ) { |
28 | print_help(); |
29 | exit(0); |
30 | } else if (StringUtil::StartsWith(arg, "--database=" )) { |
31 | auto splits = StringUtil::Split(arg, '='); |
32 | if (splits.size() != 2) { |
33 | print_help(); |
34 | exit(1); |
35 | } |
36 | dbfile = string(splits[1]); |
37 | } else if (StringUtil::StartsWith(arg, "--scale_factor=" )) { |
38 | auto splits = StringUtil::Split(arg, '='); |
39 | if (splits.size() != 2) { |
40 | print_help(); |
41 | exit(1); |
42 | } |
43 | scale_factor = atof(splits[1].c_str()); |
44 | } else { |
45 | fprintf(stderr, "Error: unknown argument %s\n" , arg.c_str()); |
46 | print_help(); |
47 | exit(1); |
48 | } |
49 | } |
50 | |
51 | if (dbfile.empty()) { |
52 | fprintf(stderr, "Error: need database file to generate\n" ); |
53 | print_help(); |
54 | exit(1); |
55 | } |
56 | |
57 | { |
58 | DuckDB duckdb(dbfile, &config); |
59 | tpch::dbgen(scale_factor, duckdb); |
60 | } // hack to checkpoint WAL |
61 | { DuckDB duckdb(dbfile, &config); } |
62 | return 0; |
63 | } |
64 | |