Skip to content

Commit

Permalink
fix: New test structure for planner
Browse files Browse the repository at this point in the history
  • Loading branch information
can-keklik committed Oct 24, 2024
1 parent 2a27ef2 commit e32053c
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 32 deletions.
1 change: 1 addition & 0 deletions lykiadb-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tracing-subscriber = "0.3"

[dev-dependencies]
criterion = { version = "0.4", features = ["html_reports"] }
test_each_file = "0.3.4"

[[bench]]
name = "interpreter"
Expand Down
30 changes: 0 additions & 30 deletions lykiadb-server/tests/planner/join.rs

This file was deleted.

26 changes: 26 additions & 0 deletions lykiadb-server/tests/planner/join/join
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#[name=two_way_simple, run=plan]>
SELECT * FROM books b
INNER JOIN categories c ON b.category_id = c.id
WHERE c.name = 'Science';
---
- filter (c.name IsEqual Str("Science")):
- join [Inner, (b.category_id IsEqual c.id)]:
- scan [books as b]
- scan [categories as c]


#[name=three_way_simple, run=plan]>

SELECT * FROM books b
INNER JOIN categories c ON b.category_id = c.id
INNER JOIN publishers AS p ON b.publisher_id = p.id
WHERE p.name = 'Springer';

---

- filter (p.name IsEqual Str("Springer")):
- join [Inner, (b.publisher_id IsEqual p.id)]:
- join [Inner, (b.category_id IsEqual c.id)]:
- scan [books as b]
- scan [categories as c]
- scan [publishers as p]
1 change: 0 additions & 1 deletion lykiadb-server/tests/planner/mod.rs

This file was deleted.

6 changes: 5 additions & 1 deletion lykiadb-server/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#![recursion_limit = "192"]
use util::run_test;
use test_each_file::test_each_file;

mod runtime;
mod planner;
mod util;

test_each_file! { in "lykiadb-server/tests/planner" => run_test }
28 changes: 28 additions & 0 deletions lykiadb-server/tests/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use lykiadb_lang::{ast::stmt::Stmt, parser::program::Program};
use lykiadb_server::plan::planner::Planner;

fn expect_plan(query: &str, expected_plan: &str) {
let mut planner = Planner::new();
let program = query.parse::<Program>().unwrap();
match *program.get_root() {
Stmt::Program { body, .. } if matches!(body.get(0), Some(Stmt::Expression { .. })) => {
if let Some(Stmt::Expression { expr, .. }) = body.get(0) {
let generated_plan = planner.build(&expr).unwrap();
assert_eq!(expected_plan, generated_plan.to_string().trim());
}
}
_ => panic!("Expected expression statement."),
}
}

pub fn run_test(input: &str) {
let parts: Vec<&str> = input.split("#[").collect();

for part in parts[1..].iter() {
let directives_and_input = part.trim();
let directives_end = directives_and_input.find('>').unwrap_or(directives_and_input.len());
let rest = directives_and_input[directives_end+1..].trim().to_string();
let io_parts: Vec<&str> = rest.split("---").collect();
expect_plan(&io_parts[0].trim(),&io_parts[1].trim());
}
}

0 comments on commit e32053c

Please sign in to comment.