Skip to content

Commit b20730a

Browse files
joseph-isaacsclaude
andcommitted
Clean up the JSONBench suite
Store the data directory directly instead of re-deriving it from the URL, run Variant Parquet preparation once and off the async runtime when preparing Vortex, make placeholder expansion a free function, and build the raw file URL from its file name. Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HXvxbPjYxoaTEqBgPLXbad
1 parent b826bf1 commit b20730a

2 files changed

Lines changed: 22 additions & 33 deletions

File tree

‎vortex-bench/src/jsonbench/data.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ const SHREDDING_MAX_DEPTH: usize = 6;
6363
/// URL of the `file_idx`-th (1-based) raw JSONBench file.
6464
pub fn raw_json_url(file_idx: usize) -> String {
6565
format!(
66-
"https://clickhouse-public-datasets.s3.amazonaws.com/bluesky/file_{file_idx:04}.json.gz"
66+
"https://clickhouse-public-datasets.s3.amazonaws.com/bluesky/{}",
67+
raw_json_name(file_idx)
6768
)
6869
}
6970

‎vortex-bench/src/jsonbench/mod.rs‎

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! Every event lives in a single `data` column of the `bluesky` table. The baseline Parquet format
88
//! stores it as a JSON string; `parquet-variant` and the Vortex formats store it as a shredded
99
//! Variant. The queries in `sql/jsonbench.sql` address JSON paths with placeholders that
10-
//! [`JsonBenchBenchmark::query_for`] expands into each engine's idiom for each format.
10+
//! [`expand_placeholders`] expands into each engine's idiom for each format.
1111
1212
pub mod data;
1313

@@ -55,6 +55,7 @@ static PLACEHOLDER: LazyLock<Regex> = LazyLock::new(|| {
5555
pub struct JsonBenchBenchmark {
5656
/// Number of one-million-row raw files the dataset is built from.
5757
n_files: usize,
58+
data_dir: PathBuf,
5859
data_url: Url,
5960
/// Directory holding the downloaded raw files, shared by every scale.
6061
raw_dir: PathBuf,
@@ -70,17 +71,12 @@ impl JsonBenchBenchmark {
7071
.map_err(|_| anyhow::anyhow!("invalid data directory {}", data_dir.display()))?;
7172
Ok(Self {
7273
n_files: scale_factor,
74+
data_dir,
7375
data_url,
7476
raw_dir: root.join("json"),
7577
})
7678
}
7779

78-
fn base_path(&self) -> anyhow::Result<PathBuf> {
79-
self.data_url
80-
.to_file_path()
81-
.map_err(|_| anyhow::anyhow!("jsonbench data URL must be a file URL"))
82-
}
83-
8480
fn raw_path(&self, file_idx: usize) -> PathBuf {
8581
self.raw_dir.join(raw_json_name(file_idx))
8682
}
@@ -90,7 +86,7 @@ impl JsonBenchBenchmark {
9086
}
9187

9288
fn shredding_schema(&self) -> anyhow::Result<ShreddingSchema> {
93-
let path = self.base_path()?.join("shredding.json");
89+
let path = self.data_dir.join("shredding.json");
9490
idempotent(&path, |tmp| {
9591
let schema = ShreddingSchema::infer(&self.raw_path(1))?;
9692
info!(
@@ -146,7 +142,7 @@ impl JsonBenchBenchmark {
146142

147143
fn prepare_variant_parquet(&self) -> anyhow::Result<PathBuf> {
148144
let shredding = self.shredding_schema()?;
149-
let dir = self.base_path()?.join(Format::ParquetVariant.name());
145+
let dir = self.data_dir.join(Format::ParquetVariant.name());
150146
self.convert_files(&dir, "parquet", |raw, output| {
151147
write_variant_parquet(raw, output, &shredding)
152148
})?;
@@ -158,8 +154,8 @@ impl JsonBenchBenchmark {
158154
Format::VortexCompact => CompactionStrategy::Compact,
159155
_ => CompactionStrategy::Default,
160156
};
161-
let variant_dir = self.prepare_variant_parquet()?;
162-
let vortex_dir = self.base_path()?.join(format.name());
157+
let variant_dir = tokio::task::block_in_place(|| self.prepare_variant_parquet())?;
158+
let vortex_dir = self.data_dir.join(format.name());
163159
fs::create_dir_all(&vortex_dir)?;
164160
for file_idx in self.file_indices() {
165161
let stem = output_stem(file_idx);
@@ -171,18 +167,16 @@ impl JsonBenchBenchmark {
171167
}
172168
Ok(())
173169
}
170+
}
174171

175-
/// Expand `{str:path}` and `{i64:path}` placeholders into `engine`'s idiom for reading that
176-
/// JSON path from `format`.
177-
pub fn expand_placeholders(engine: Engine, format: Format, query: &str) -> String {
178-
PLACEHOLDER
179-
.replace_all(query, |caps: &Captures| {
180-
let ty = &caps[1];
181-
let path = &caps[2];
182-
expand_path(engine, format, ty, path)
183-
})
184-
.into_owned()
185-
}
172+
/// Expand `{str:path}` and `{i64:path}` placeholders into `engine`'s idiom for reading that JSON
173+
/// path from `format`.
174+
pub fn expand_placeholders(engine: Engine, format: Format, query: &str) -> String {
175+
PLACEHOLDER
176+
.replace_all(query, |caps: &Captures| {
177+
expand_path(engine, format, &caps[1], &caps[2])
178+
})
179+
.into_owned()
186180
}
187181

188182
/// The SQL expression reading JSON `path` as `ty` (`str` or `i64`) on `engine` from `format`.
@@ -240,7 +234,7 @@ impl Benchmark for JsonBenchBenchmark {
240234
}
241235

242236
fn query_for(&self, engine: Engine, format: Format, query: &str) -> String {
243-
Self::expand_placeholders(engine, format, query)
237+
expand_placeholders(engine, format, query)
244238
}
245239

246240
async fn generate_base_data(&self) -> anyhow::Result<()> {
@@ -267,7 +261,7 @@ impl Benchmark for JsonBenchBenchmark {
267261
.await?;
268262
}
269263

270-
let parquet_dir = self.base_path()?.join(Format::Parquet.name());
264+
let parquet_dir = self.data_dir.join(Format::Parquet.name());
271265
tokio::task::block_in_place(|| {
272266
self.shredding_schema()?;
273267
self.convert_files(&parquet_dir, "parquet", write_json_parquet)
@@ -279,10 +273,7 @@ impl Benchmark for JsonBenchBenchmark {
279273
Format::ParquetVariant => {
280274
tokio::task::block_in_place(|| self.prepare_variant_parquet())?;
281275
}
282-
Format::OnDiskVortex | Format::VortexCompact => {
283-
tokio::task::block_in_place(|| self.prepare_variant_parquet())?;
284-
self.prepare_vortex(format).await?;
285-
}
276+
Format::OnDiskVortex | Format::VortexCompact => self.prepare_vortex(format).await?,
286277
_ => {}
287278
}
288279
Ok(())
@@ -349,9 +340,6 @@ mod tests {
349340
#[case] format: Format,
350341
#[case] expected: &str,
351342
) {
352-
assert_eq!(
353-
JsonBenchBenchmark::expand_placeholders(engine, format, QUERY),
354-
expected
355-
);
343+
assert_eq!(expand_placeholders(engine, format, QUERY), expected);
356344
}
357345
}

0 commit comments

Comments
 (0)