mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-24 08:43:43 +00:00
Add MySql, BigQuery to all dialects (#697)
* Add MySql, BigQuery to all dialects * move unsupported on mysql from common
This commit is contained in:
parent
f7817bc7c2
commit
0428ac742b
12 changed files with 1200 additions and 164 deletions
|
@ -115,6 +115,115 @@ fn parse_cast_type() {
|
|||
bigquery().verified_only_select(sql);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_like() {
|
||||
fn chk(negated: bool) {
|
||||
let sql = &format!(
|
||||
"SELECT * FROM customers WHERE name {}LIKE '%a'",
|
||||
if negated { "NOT " } else { "" }
|
||||
);
|
||||
let select = bigquery().verified_only_select(sql);
|
||||
assert_eq!(
|
||||
Expr::Like {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("name"))),
|
||||
negated,
|
||||
pattern: Box::new(Expr::Value(Value::SingleQuotedString("%a".to_string()))),
|
||||
escape_char: None,
|
||||
},
|
||||
select.selection.unwrap()
|
||||
);
|
||||
|
||||
// Test with escape char
|
||||
let sql = &format!(
|
||||
"SELECT * FROM customers WHERE name {}LIKE '%a' ESCAPE '\\'",
|
||||
if negated { "NOT " } else { "" }
|
||||
);
|
||||
let select = bigquery().verified_only_select(sql);
|
||||
assert_eq!(
|
||||
Expr::Like {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("name"))),
|
||||
negated,
|
||||
pattern: Box::new(Expr::Value(Value::SingleQuotedString("%a".to_string()))),
|
||||
escape_char: Some('\\'),
|
||||
},
|
||||
select.selection.unwrap()
|
||||
);
|
||||
|
||||
// This statement tests that LIKE and NOT LIKE have the same precedence.
|
||||
// This was previously mishandled (#81).
|
||||
let sql = &format!(
|
||||
"SELECT * FROM customers WHERE name {}LIKE '%a' IS NULL",
|
||||
if negated { "NOT " } else { "" }
|
||||
);
|
||||
let select = bigquery().verified_only_select(sql);
|
||||
assert_eq!(
|
||||
Expr::IsNull(Box::new(Expr::Like {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("name"))),
|
||||
negated,
|
||||
pattern: Box::new(Expr::Value(Value::SingleQuotedString("%a".to_string()))),
|
||||
escape_char: None,
|
||||
})),
|
||||
select.selection.unwrap()
|
||||
);
|
||||
}
|
||||
chk(false);
|
||||
chk(true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_similar_to() {
|
||||
fn chk(negated: bool) {
|
||||
let sql = &format!(
|
||||
"SELECT * FROM customers WHERE name {}SIMILAR TO '%a'",
|
||||
if negated { "NOT " } else { "" }
|
||||
);
|
||||
let select = bigquery().verified_only_select(sql);
|
||||
assert_eq!(
|
||||
Expr::SimilarTo {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("name"))),
|
||||
negated,
|
||||
pattern: Box::new(Expr::Value(Value::SingleQuotedString("%a".to_string()))),
|
||||
escape_char: None,
|
||||
},
|
||||
select.selection.unwrap()
|
||||
);
|
||||
|
||||
// Test with escape char
|
||||
let sql = &format!(
|
||||
"SELECT * FROM customers WHERE name {}SIMILAR TO '%a' ESCAPE '\\'",
|
||||
if negated { "NOT " } else { "" }
|
||||
);
|
||||
let select = bigquery().verified_only_select(sql);
|
||||
assert_eq!(
|
||||
Expr::SimilarTo {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("name"))),
|
||||
negated,
|
||||
pattern: Box::new(Expr::Value(Value::SingleQuotedString("%a".to_string()))),
|
||||
escape_char: Some('\\'),
|
||||
},
|
||||
select.selection.unwrap()
|
||||
);
|
||||
|
||||
// This statement tests that SIMILAR TO and NOT SIMILAR TO have the same precedence.
|
||||
let sql = &format!(
|
||||
"SELECT * FROM customers WHERE name {}SIMILAR TO '%a' ESCAPE '\\' IS NULL",
|
||||
if negated { "NOT " } else { "" }
|
||||
);
|
||||
let select = bigquery().verified_only_select(sql);
|
||||
assert_eq!(
|
||||
Expr::IsNull(Box::new(Expr::SimilarTo {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("name"))),
|
||||
negated,
|
||||
pattern: Box::new(Expr::Value(Value::SingleQuotedString("%a".to_string()))),
|
||||
escape_char: Some('\\'),
|
||||
})),
|
||||
select.selection.unwrap()
|
||||
);
|
||||
}
|
||||
chk(false);
|
||||
chk(true);
|
||||
}
|
||||
|
||||
fn bigquery() -> TestedDialects {
|
||||
TestedDialects {
|
||||
dialects: vec![Box::new(BigQueryDialect {})],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue