mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-14 03:54:59 +00:00
feat: dollar-quoted strings support (#772)
* feat: support dollar-quoted strings * remove comment * unused code * removed debugging * added tests * fmt * clippy * updated tests
This commit is contained in:
parent
0c9ec40082
commit
072ccc0d76
5 changed files with 210 additions and 33 deletions
|
@ -2507,3 +2507,84 @@ fn parse_drop_function() {
|
|||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_dollar_quoted_string() {
|
||||
let sql = "SELECT $$hello$$, $tag_name$world$tag_name$, $$Foo$Bar$$, $$Foo$Bar$$col_name, $$$$, $tag_name$$tag_name$";
|
||||
|
||||
let stmt = pg().parse_sql_statements(sql).unwrap();
|
||||
|
||||
let projection = match stmt.get(0).unwrap() {
|
||||
Statement::Query(query) => match &*query.body {
|
||||
SetExpr::Select(select) => &select.projection,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
&Expr::Value(Value::DollarQuotedString(DollarQuotedString {
|
||||
tag: None,
|
||||
value: "hello".into()
|
||||
})),
|
||||
expr_from_projection(&projection[0])
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
&Expr::Value(Value::DollarQuotedString(DollarQuotedString {
|
||||
tag: Some("tag_name".into()),
|
||||
value: "world".into()
|
||||
})),
|
||||
expr_from_projection(&projection[1])
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
&Expr::Value(Value::DollarQuotedString(DollarQuotedString {
|
||||
tag: None,
|
||||
value: "Foo$Bar".into()
|
||||
})),
|
||||
expr_from_projection(&projection[2])
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
projection[3],
|
||||
SelectItem::ExprWithAlias {
|
||||
expr: Expr::Value(Value::DollarQuotedString(DollarQuotedString {
|
||||
tag: None,
|
||||
value: "Foo$Bar".into(),
|
||||
})),
|
||||
alias: Ident {
|
||||
value: "col_name".into(),
|
||||
quote_style: None,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
expr_from_projection(&projection[4]),
|
||||
&Expr::Value(Value::DollarQuotedString(DollarQuotedString {
|
||||
tag: None,
|
||||
value: "".into()
|
||||
})),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
expr_from_projection(&projection[5]),
|
||||
&Expr::Value(Value::DollarQuotedString(DollarQuotedString {
|
||||
tag: Some("tag_name".into()),
|
||||
value: "".into()
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_incorrect_dollar_quoted_string() {
|
||||
let sql = "SELECT $x$hello$$";
|
||||
assert!(pg().parse_sql_statements(sql).is_err());
|
||||
|
||||
let sql = "SELECT $hello$$";
|
||||
assert!(pg().parse_sql_statements(sql).is_err());
|
||||
|
||||
let sql = "SELECT $$$";
|
||||
assert!(pg().parse_sql_statements(sql).is_err());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue