datafusion-sqlparse/tests/sqlparser_ansi.rs
Nickolay Ponomarev d8173d4196 Extract ASTNode::SQLSelect to a separate struct (1/5)
This will allow re-using it for SQLStatement in a later commit.

(Also split the new struct into a separate file, other query-related
types will be moved here in a follow-up commit.)
2019-01-31 03:57:17 +03:00

28 lines
759 B
Rust

extern crate log;
extern crate sqlparser;
use sqlparser::dialect::AnsiSqlDialect;
use sqlparser::sqlast::*;
use sqlparser::sqlparser::*;
use sqlparser::sqltokenizer::*;
#[test]
fn parse_simple_select() {
let sql = String::from("SELECT id, fname, lname FROM customer WHERE id = 1");
let ast = parse_sql(&sql);
match ast {
ASTNode::SQLSelect(SQLSelect { projection, .. }) => {
assert_eq!(3, projection.len());
}
_ => assert!(false),
}
}
fn parse_sql(sql: &str) -> ASTNode {
let dialect = AnsiSqlDialect {};
let mut tokenizer = Tokenizer::new(&dialect, &sql);
let tokens = tokenizer.tokenize().unwrap();
let mut parser = Parser::new(tokens);
let ast = parser.parse().unwrap();
ast
}