-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathmain.rs
More file actions
195 lines (159 loc) · 5.53 KB
/
main.rs
File metadata and controls
195 lines (159 loc) · 5.53 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
mod validation;
use std::path::PathBuf;
use clap::Parser;
use clap::value_parser;
use duckdb_bench::DuckClient;
use tokio::runtime::Runtime;
use vortex::metrics::tracing::set_global_labels;
use vortex_bench::BenchmarkArg;
use vortex_bench::CompactionStrategy;
use vortex_bench::Engine;
use vortex_bench::Format;
use vortex_bench::Opt;
use vortex_bench::Opts;
use vortex_bench::conversions::convert_parquet_directory_to_vortex;
use vortex_bench::create_benchmark;
use vortex_bench::create_output_writer;
use vortex_bench::display::DisplayFormat;
use vortex_bench::runner::BenchmarkMode;
use vortex_bench::runner::SqlBenchmarkRunner;
use vortex_bench::runner::filter_queries;
use vortex_bench::setup_logging_and_tracing;
/// Common arguments shared across benchmarks
#[derive(Parser)]
struct Args {
#[arg(value_enum)]
benchmark: BenchmarkArg,
#[arg(short, long, default_value_t = 5)]
iterations: usize,
#[arg(short, long)]
threads: Option<usize>,
#[arg(short, long)]
verbose: bool,
#[arg(long)]
tracing: bool,
#[arg(short, long, default_value_t, value_enum)]
display_format: DisplayFormat,
#[arg(long, default_value_t = false)]
delete_duckdb_database: bool,
#[arg(short, long, value_delimiter = ',')]
queries: Option<Vec<usize>>,
#[arg(short, long, value_delimiter = ',')]
exclude_queries: Option<Vec<usize>>,
#[arg(short)]
output_path: Option<PathBuf>,
#[arg(long, default_value_t = false)]
track_memory: bool,
#[arg(long, default_value_t = false)]
hide_progress_bar: bool,
#[arg(long, value_delimiter = ',', value_parser = value_parser!(Format))]
formats: Vec<Format>,
#[arg(long = "opt", value_delimiter = ',', value_parser = value_parser!(Opt))]
options: Vec<Opt>,
/// Print EXPLAIN output for each query instead of running benchmarks.
#[arg(long, default_value_t = false)]
explain: bool,
#[arg(
long,
default_value_t = false,
help = "Whether to reuse the DuckDB connection across iterations. Helpful when profiling \
to keep all work on the same threads"
)]
reuse: bool,
}
fn main() -> anyhow::Result<()> {
let args = Args::parse();
let opts = Opts::from(args.options);
setup_logging_and_tracing(args.verbose, args.tracing)?;
let benchmark = create_benchmark(args.benchmark, &opts)?;
let filtered_queries = filter_queries(
benchmark.queries()?,
args.queries.as_ref(),
args.exclude_queries.as_ref(),
);
if args.formats.is_empty() {
anyhow::bail!("provide a format with --formats");
}
// Generate Vortex files from Parquet for any Vortex formats requested
if benchmark.data_url().scheme() == "file" {
// This is ugly, but otherwise some complicated async interaction might result in a deadlock
let runtime = Runtime::new()?;
runtime.block_on(async {
benchmark.generate_base_data().await?;
let base_path = benchmark
.data_url()
.to_file_path()
.map_err(|_| anyhow::anyhow!("Invalid file URL: {}", benchmark.data_url()))?;
for format in args.formats.iter().copied() {
match format {
Format::OnDiskVortex => {
convert_parquet_directory_to_vortex(
&base_path,
CompactionStrategy::Default,
)
.await?;
}
Format::VortexCompact => {
convert_parquet_directory_to_vortex(
&base_path,
CompactionStrategy::Compact,
)
.await?;
}
// OnDiskDuckDB tables are created during register_tables by loading from Parquet
_ => {}
}
}
anyhow::Ok(())
})?;
}
let mut runner = SqlBenchmarkRunner::new(
&*benchmark,
Engine::DuckDB,
args.formats.clone(),
args.track_memory,
args.hide_progress_bar,
)?;
let benchmark_name = benchmark.dataset().to_string();
let mode = if args.explain {
BenchmarkMode::Explain
} else {
BenchmarkMode::Run {
iterations: args.iterations,
}
};
runner.run_all(
&filtered_queries,
mode,
|format| {
let ctx = DuckClient::new(
&*benchmark,
format,
args.delete_duckdb_database,
args.threads,
)?;
ctx.register_tables(&*benchmark, format)?;
Ok(ctx)
},
|ctx, query_idx, format, query| {
set_global_labels(vec![
("format", format.to_string()),
("benchmark_name", benchmark_name.clone()),
("query_idx", query_idx.to_string()),
]);
// Make sure to reopen the duckdb connection between iterations
if !args.reuse {
ctx.reopen()?;
}
ctx.execute_query_result(query)
},
)?;
if !args.explain {
let benchmark_id = format!("duckdb-{}", benchmark.dataset_name());
let writer = create_output_writer(&args.display_format, args.output_path, &benchmark_id)?;
runner.export_to(&args.display_format, writer)?;
}
Ok(())
}