mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-30 18:57:21 +00:00
Parse LIKE patterns as Expr not Value (#579)
This commit is contained in:
parent
fc71719719
commit
eb7f1b005e
3 changed files with 73 additions and 28 deletions
|
@ -862,7 +862,7 @@ fn parse_not_precedence() {
|
|||
expr: Box::new(Expr::Like {
|
||||
expr: Box::new(Expr::Value(Value::SingleQuotedString("a".into()))),
|
||||
negated: true,
|
||||
pattern: Box::new(Value::SingleQuotedString("b".into())),
|
||||
pattern: Box::new(Expr::Value(Value::SingleQuotedString("b".into()))),
|
||||
escape_char: None
|
||||
}),
|
||||
},
|
||||
|
@ -895,7 +895,7 @@ fn parse_like() {
|
|||
Expr::Like {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("name"))),
|
||||
negated,
|
||||
pattern: Box::new(Value::SingleQuotedString("%a".to_string())),
|
||||
pattern: Box::new(Expr::Value(Value::SingleQuotedString("%a".to_string()))),
|
||||
escape_char: None
|
||||
},
|
||||
select.selection.unwrap()
|
||||
|
@ -911,7 +911,7 @@ fn parse_like() {
|
|||
Expr::Like {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("name"))),
|
||||
negated,
|
||||
pattern: Box::new(Value::SingleQuotedString("%a".to_string())),
|
||||
pattern: Box::new(Expr::Value(Value::SingleQuotedString("%a".to_string()))),
|
||||
escape_char: Some('\\')
|
||||
},
|
||||
select.selection.unwrap()
|
||||
|
@ -928,7 +928,7 @@ fn parse_like() {
|
|||
Expr::IsNull(Box::new(Expr::Like {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("name"))),
|
||||
negated,
|
||||
pattern: Box::new(Value::SingleQuotedString("%a".to_string())),
|
||||
pattern: Box::new(Expr::Value(Value::SingleQuotedString("%a".to_string()))),
|
||||
escape_char: None
|
||||
})),
|
||||
select.selection.unwrap()
|
||||
|
@ -938,6 +938,45 @@ fn parse_like() {
|
|||
chk(true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_null_like() {
|
||||
let sql = "SELECT \
|
||||
column1 LIKE NULL AS col_null, \
|
||||
NULL LIKE column1 AS null_col \
|
||||
FROM customers";
|
||||
let select = verified_only_select(sql);
|
||||
assert_eq!(
|
||||
SelectItem::ExprWithAlias {
|
||||
expr: Expr::Like {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("column1"))),
|
||||
negated: false,
|
||||
pattern: Box::new(Expr::Value(Value::Null)),
|
||||
escape_char: None
|
||||
},
|
||||
alias: Ident {
|
||||
value: "col_null".to_owned(),
|
||||
quote_style: None
|
||||
}
|
||||
},
|
||||
select.projection[0]
|
||||
);
|
||||
assert_eq!(
|
||||
SelectItem::ExprWithAlias {
|
||||
expr: Expr::Like {
|
||||
expr: Box::new(Expr::Value(Value::Null)),
|
||||
negated: false,
|
||||
pattern: Box::new(Expr::Identifier(Ident::new("column1"))),
|
||||
escape_char: None
|
||||
},
|
||||
alias: Ident {
|
||||
value: "null_col".to_owned(),
|
||||
quote_style: None
|
||||
}
|
||||
},
|
||||
select.projection[1]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_ilike() {
|
||||
fn chk(negated: bool) {
|
||||
|
@ -950,7 +989,7 @@ fn parse_ilike() {
|
|||
Expr::ILike {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("name"))),
|
||||
negated,
|
||||
pattern: Box::new(Value::SingleQuotedString("%a".to_string())),
|
||||
pattern: Box::new(Expr::Value(Value::SingleQuotedString("%a".to_string()))),
|
||||
escape_char: None
|
||||
},
|
||||
select.selection.unwrap()
|
||||
|
@ -966,7 +1005,7 @@ fn parse_ilike() {
|
|||
Expr::ILike {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("name"))),
|
||||
negated,
|
||||
pattern: Box::new(Value::SingleQuotedString("%a".to_string())),
|
||||
pattern: Box::new(Expr::Value(Value::SingleQuotedString("%a".to_string()))),
|
||||
escape_char: Some('^')
|
||||
},
|
||||
select.selection.unwrap()
|
||||
|
@ -983,7 +1022,7 @@ fn parse_ilike() {
|
|||
Expr::IsNull(Box::new(Expr::ILike {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("name"))),
|
||||
negated,
|
||||
pattern: Box::new(Value::SingleQuotedString("%a".to_string())),
|
||||
pattern: Box::new(Expr::Value(Value::SingleQuotedString("%a".to_string()))),
|
||||
escape_char: None
|
||||
})),
|
||||
select.selection.unwrap()
|
||||
|
@ -1005,7 +1044,7 @@ fn parse_similar_to() {
|
|||
Expr::SimilarTo {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("name"))),
|
||||
negated,
|
||||
pattern: Box::new(Value::SingleQuotedString("%a".to_string())),
|
||||
pattern: Box::new(Expr::Value(Value::SingleQuotedString("%a".to_string()))),
|
||||
escape_char: None
|
||||
},
|
||||
select.selection.unwrap()
|
||||
|
@ -1021,7 +1060,7 @@ fn parse_similar_to() {
|
|||
Expr::SimilarTo {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("name"))),
|
||||
negated,
|
||||
pattern: Box::new(Value::SingleQuotedString("%a".to_string())),
|
||||
pattern: Box::new(Expr::Value(Value::SingleQuotedString("%a".to_string()))),
|
||||
escape_char: Some('\\')
|
||||
},
|
||||
select.selection.unwrap()
|
||||
|
@ -1037,7 +1076,7 @@ fn parse_similar_to() {
|
|||
Expr::IsNull(Box::new(Expr::SimilarTo {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("name"))),
|
||||
negated,
|
||||
pattern: Box::new(Value::SingleQuotedString("%a".to_string())),
|
||||
pattern: Box::new(Expr::Value(Value::SingleQuotedString("%a".to_string()))),
|
||||
escape_char: Some('\\')
|
||||
})),
|
||||
select.selection.unwrap()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue