-
Notifications
You must be signed in to change notification settings - Fork 331
feat(sqllogictest): Add sqllogictest schedule definition and parsing #1630
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e430e24
Introduce scheduler for sqllogictests
liurenjie1024 8ff74fe
Add schedule definition and parsing in sql logic test
lliangyu-lin c60e4d8
Remove unnecessary deps
lliangyu-lin 7a5120e
Update logging & slt relative path
0c0b98b
Merge branch 'main' into sqllogic-schedule
lliangyu-lin 3591446
Update redundant pathbuf
lliangyu-lin d7e3277
Merge branch 'main' into sqllogic-schedule
liurenjie1024 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -22,3 +22,5 @@ | |
mod engine; | ||
#[allow(dead_code)] | ||
mod error; | ||
#[allow(dead_code)] | ||
mod schedule; |
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,197 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use std::collections::HashMap; | ||
use std::fs::read_to_string; | ||
use std::path::{Path, PathBuf}; | ||
|
||
use anyhow::{Context, anyhow}; | ||
use serde::{Deserialize, Serialize}; | ||
use toml::{Table as TomlTable, Value}; | ||
use tracing::info; | ||
|
||
use crate::engine::Engine; | ||
|
||
pub struct Schedule { | ||
/// Engine names to engine instances | ||
engines: HashMap<String, Engine>, | ||
/// List of test steps to run | ||
steps: Vec<Step>, | ||
/// Path of the schedule file | ||
schedule_file: String, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Step { | ||
/// Engine name | ||
engine: String, | ||
/// Stl file path | ||
slt: String, | ||
} | ||
|
||
impl Schedule { | ||
pub fn new(engines: HashMap<String, Engine>, steps: Vec<Step>, schedule_file: String) -> Self { | ||
Self { | ||
engines, | ||
steps, | ||
schedule_file, | ||
} | ||
} | ||
|
||
pub async fn from_file<P: AsRef<Path>>(path: P) -> anyhow::Result<Self> { | ||
let path_str = path.as_ref().to_string_lossy().to_string(); | ||
let content = read_to_string(path)?; | ||
let toml_value = content.parse::<Value>()?; | ||
let toml_table = toml_value | ||
.as_table() | ||
.ok_or_else(|| anyhow!("Schedule file must be a TOML table"))?; | ||
|
||
let engines = Schedule::parse_engines(toml_table).await?; | ||
let steps = Schedule::parse_steps(toml_table)?; | ||
|
||
Ok(Self::new(engines, steps, path_str)) | ||
} | ||
|
||
pub async fn run(mut self) -> anyhow::Result<()> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a log about current schedule file? |
||
info!("Starting test run with schedule: {}", self.schedule_file); | ||
|
||
for (idx, step) in self.steps.iter().enumerate() { | ||
info!( | ||
"Running step {}/{}, using engine {}, slt file path: {}", | ||
idx + 1, | ||
self.steps.len(), | ||
&step.engine, | ||
&step.slt | ||
); | ||
|
||
let engine = self | ||
.engines | ||
.get_mut(&step.engine) | ||
.ok_or_else(|| anyhow!("Engine {} not found", step.engine))?; | ||
|
||
let step_sql_path = PathBuf::from(format!( | ||
"{}/testdata/slts/{}", | ||
env!("CARGO_MANIFEST_DIR"), | ||
&step.slt | ||
)); | ||
|
||
engine.run_slt_file(&step_sql_path).await?; | ||
|
||
info!( | ||
"Completed step {}/{}, engine {}, slt file path: {}", | ||
idx + 1, | ||
self.steps.len(), | ||
&step.engine, | ||
&step.slt | ||
); | ||
} | ||
Ok(()) | ||
} | ||
|
||
async fn parse_engines(table: &TomlTable) -> anyhow::Result<HashMap<String, Engine>> { | ||
let engines_tbl = table | ||
.get("engines") | ||
.with_context(|| "Schedule file must have an 'engines' table")? | ||
.as_table() | ||
.ok_or_else(|| anyhow!("'engines' must be a table"))?; | ||
|
||
let mut engines = HashMap::new(); | ||
|
||
for (name, engine_val) in engines_tbl { | ||
let cfg_tbl = engine_val | ||
.as_table() | ||
.ok_or_else(|| anyhow!("Config of engine '{name}' is not a table"))? | ||
.clone(); | ||
|
||
let engine = Engine::new(cfg_tbl) | ||
.await | ||
.with_context(|| format!("Failed to construct engine '{name}'"))?; | ||
|
||
if engines.insert(name.clone(), engine).is_some() { | ||
return Err(anyhow!("Duplicate engine '{name}'")); | ||
} | ||
} | ||
|
||
Ok(engines) | ||
} | ||
|
||
fn parse_steps(table: &TomlTable) -> anyhow::Result<Vec<Step>> { | ||
let steps_val = table | ||
.get("steps") | ||
.with_context(|| "Schedule file must have a 'steps' array")?; | ||
|
||
let steps: Vec<Step> = steps_val | ||
.clone() | ||
.try_into() | ||
.with_context(|| "Failed to deserialize steps")?; | ||
|
||
Ok(steps) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use toml::Table as TomlTable; | ||
|
||
use crate::schedule::Schedule; | ||
|
||
#[test] | ||
fn test_parse_steps() { | ||
let input = r#" | ||
[[steps]] | ||
engine = "datafusion" | ||
slt = "test.slt" | ||
|
||
[[steps]] | ||
engine = "spark" | ||
slt = "test2.slt" | ||
"#; | ||
|
||
let tbl: TomlTable = toml::from_str(input).unwrap(); | ||
let steps = Schedule::parse_steps(&tbl).unwrap(); | ||
|
||
assert_eq!(steps.len(), 2); | ||
assert_eq!(steps[0].engine, "datafusion"); | ||
assert_eq!(steps[0].slt, "test.slt"); | ||
assert_eq!(steps[1].engine, "spark"); | ||
assert_eq!(steps[1].slt, "test2.slt"); | ||
} | ||
|
||
#[test] | ||
fn test_parse_steps_empty() { | ||
let input = r#" | ||
[[steps]] | ||
"#; | ||
|
||
let tbl: TomlTable = toml::from_str(input).unwrap(); | ||
let steps = Schedule::parse_steps(&tbl); | ||
|
||
assert!(steps.is_err()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_parse_engines_invalid_table() { | ||
let toml_content = r#" | ||
engines = "not_a_table" | ||
"#; | ||
|
||
let table: TomlTable = toml::from_str(toml_content).unwrap(); | ||
let result = Schedule::parse_engines(&table).await; | ||
|
||
assert!(result.is_err()); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we move this out of trait?