-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
26 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,17 +1,18 @@ | ||
use crate::error::BustubxResult; | ||
use sqlparser::{ast::Statement, dialect::PostgreSqlDialect, parser::Parser}; | ||
use tracing::span; | ||
|
||
pub fn parse_sql(sql: &str) -> BustubxResult<Vec<Statement>> { | ||
let stmts = Parser::parse_sql(&PostgreSqlDialect {}, sql)?; | ||
Ok(stmts) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
#[test] | ||
pub fn test_sql() { | ||
let sql = "select * from t1, t2, t3 inner join t4 on t3.id = t4.id"; | ||
pub fn test_parser() { | ||
let sql = "select * from (select * from t1)"; | ||
let stmts = super::parse_sql(sql).unwrap(); | ||
println!("{:?}", stmts); | ||
println!("{:#?}", stmts[0]); | ||
} | ||
} |
This file contains 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 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,17 @@ | ||
statement ok | ||
create table t1 (a int, b int) | ||
|
||
statement ok | ||
insert into t1 values (2, 3), (5, 4) | ||
|
||
query II rowsort | ||
select * from (select * from t1) | ||
---- | ||
2 3 | ||
5 4 | ||
|
||
query II rowsort | ||
select * from (select b from t1) | ||
---- | ||
3 | ||
4 |