-
Notifications
You must be signed in to change notification settings - Fork 186
Own SQL benchmark suite #8719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
myrrc
wants to merge
1
commit into
develop
Choose a base branch
from
myrrc/sql-bench
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Own SQL benchmark suite #8719
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| -- As this aggregation has a filter, Vortex has to use a linear scan. Once stats | ||
| -- are propagated to arrays, this should use zone maps to aggregate instead of | ||
| -- decoding and processing each row. | ||
| SELECT sum(col) FROM test WHERE col2 > 0 AND col2 < 1000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| -- When Footer changes land, vortex-duckdb should populate statistics from | ||
| -- Footer without loading and decoding the data. | ||
| SELECT sum(col) FROM test; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| -- Script that prepares Parquet data for our SQL microbenchmarks. | ||
|
|
||
| COPY ( | ||
| SELECT | ||
| i % 1000 AS col, | ||
| (i * 2654435761) % 100000 AS col2 | ||
| FROM range(25000000) t(i) | ||
| ) TO 'test.parquet' (FORMAT parquet); |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| //! Benchmark that runs queries which aren't part of any existing benchmark | ||
| //! suite but which performance we want to track. | ||
|
|
||
| use std::fs; | ||
| use std::path::PathBuf; | ||
| use std::process::Command; | ||
|
|
||
| use anyhow::Context; | ||
| use anyhow::Result; | ||
| use anyhow::anyhow; | ||
| use anyhow::bail; | ||
| use glob::Pattern; | ||
| use tracing::debug; | ||
| use url::Url; | ||
| use vortex::error::VortexExpect; | ||
|
|
||
| use crate::Benchmark; | ||
| use crate::BenchmarkDataset; | ||
| use crate::Format; | ||
| use crate::TableSpec; | ||
| use crate::bench_dir; | ||
|
|
||
| // Path to script that creates Parquet data | ||
| const INIT_SQL: &str = "init.sql"; | ||
|
|
||
| pub struct VortexBenchmark { | ||
| data_url: Url, | ||
| queries_dir: PathBuf, | ||
| query: Option<PathBuf>, | ||
| } | ||
|
|
||
| impl VortexBenchmark { | ||
| pub fn new() -> Result<Self> { | ||
| let queries_dir = bench_dir().join("sql").join("vortex"); | ||
| let data_url = Url::from_directory_path(&queries_dir) | ||
| .map_err(|_| anyhow!("cannot build URL for {}", queries_dir.display()))?; | ||
| Ok(Self { | ||
| data_url, | ||
| queries_dir, | ||
| query: None, | ||
| }) | ||
| } | ||
|
|
||
| // Same as new(), but run only for "query" SQL file | ||
| pub fn with_query(mut self, query: &str) -> Result<Self> { | ||
| let as_path = PathBuf::from(query); | ||
| let path = if as_path.is_file() { | ||
| as_path | ||
| } else if query.ends_with(".sql") { | ||
| self.queries_dir.join(query) | ||
| } else { | ||
| self.queries_dir.join(format!("{query}.sql")) | ||
| }; | ||
| if !path.is_file() { | ||
| bail!("{query} file not found in {}", self.queries_dir.display()); | ||
| } | ||
| self.query = Some(path); | ||
| Ok(self) | ||
| } | ||
|
|
||
| fn query_files(&self) -> Result<Vec<PathBuf>> { | ||
| if let Some(query) = &self.query { | ||
| return Ok(vec![query.clone()]); | ||
| } | ||
|
|
||
| let entries = fs::read_dir(&self.queries_dir) | ||
| .with_context(|| format!("cannot list queries in {}", self.queries_dir.display()))? | ||
| .collect::<std::io::Result<Vec<_>>>()?; | ||
|
|
||
| let mut files: Vec<PathBuf> = entries | ||
| .into_iter() | ||
| .map(|entry| entry.path()) | ||
| .filter(|path| { | ||
| path.extension().is_some_and(|ext| ext == "sql") | ||
| && path.file_name().is_some_and(|name| name != INIT_SQL) | ||
| }) | ||
| .collect(); | ||
| files.sort(); | ||
|
|
||
| if files.is_empty() { | ||
| bail!("no query files found in {}", self.queries_dir.display()); | ||
| } | ||
| Ok(files) | ||
| } | ||
| } | ||
|
|
||
| #[async_trait::async_trait] | ||
| impl Benchmark for VortexBenchmark { | ||
| fn queries(&self) -> Result<Vec<(usize, String)>> { | ||
| self.query_files()? | ||
| .iter() | ||
| .map(|path| { | ||
| let idx = path | ||
| .file_name() | ||
| .vortex_expect("no file name") | ||
| .to_str() | ||
| .vortex_expect("not utf-8") | ||
| .split_once("_") | ||
| .vortex_expect("query without a number") | ||
| .0 | ||
| .parse::<usize>()?; | ||
| let query = fs::read_to_string(path) | ||
| .with_context(|| format!("cannot read query {}", path.display()))?; | ||
| debug!(idx, file = %path.display(), "Loaded vortex query"); | ||
| Ok((idx, query)) | ||
| }) | ||
| .collect() | ||
| } | ||
|
|
||
| async fn generate_base_data(&self) -> Result<()> { | ||
| let parquet_dir = self.queries_dir.join(Format::Parquet.name()); | ||
| fs::create_dir_all(&parquet_dir)?; | ||
| let parquet_file = parquet_dir.join("test.parquet"); | ||
|
|
||
| if parquet_file.exists() { | ||
| debug!("Parquet data present in {}", parquet_dir.display()); | ||
| return Ok(()); | ||
| } | ||
|
|
||
| let init_path = self.queries_dir.join(INIT_SQL); | ||
| let script = fs::read_to_string(&init_path) | ||
| .with_context(|| format!("cannot read {}", init_path.display()))?; | ||
|
|
||
| let output = Command::new("duckdb") | ||
| .current_dir(&parquet_dir) | ||
| .arg("-c") | ||
| .arg(&script) | ||
| .output() | ||
| .context("cannot run duckdb")?; | ||
| if !output.status.success() { | ||
| bail!( | ||
| "duckdb {INIT_SQL} failed: stdout={:?} stderr={:?}", | ||
| String::from_utf8_lossy(&output.stdout), | ||
| String::from_utf8_lossy(&output.stderr), | ||
| ); | ||
| } | ||
|
|
||
| if !parquet_file.exists() { | ||
| bail!("{INIT_SQL} did not create Parquet files"); | ||
| } | ||
|
|
||
| debug!("Parquet data generated in {}", parquet_dir.display()); | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn dataset(&self) -> BenchmarkDataset { | ||
| BenchmarkDataset::VortexQueries | ||
| } | ||
|
|
||
| fn dataset_name(&self) -> &str { | ||
| "vortex" | ||
| } | ||
|
|
||
| fn dataset_display(&self) -> String { | ||
| "vortex".to_owned() | ||
| } | ||
|
|
||
| fn data_url(&self) -> &Url { | ||
| &self.data_url | ||
| } | ||
|
|
||
| fn table_specs(&self) -> Vec<TableSpec> { | ||
| vec![TableSpec::new("test", None)] | ||
| } | ||
|
|
||
| fn pattern(&self, table_name: &str, format: Format) -> Option<Pattern> { | ||
| Some( | ||
| Pattern::new(&format!("{table_name}.{}", format.ext())) | ||
| .expect("table name is a valid identifier"), | ||
| ) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.