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
1212pub mod data;
1313
@@ -55,6 +55,7 @@ static PLACEHOLDER: LazyLock<Regex> = LazyLock::new(|| {
5555pub 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