mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-30 10:47:22 +00:00
fix: parsing JsonOperator
(#913)
This commit is contained in:
parent
c8b6e7f2c7
commit
df45db1375
2 changed files with 112 additions and 34 deletions
|
@ -1113,6 +1113,41 @@ fn parse_unary_math_with_multiply() {
|
|||
);
|
||||
}
|
||||
|
||||
fn pg_and_generic() -> TestedDialects {
|
||||
TestedDialects {
|
||||
dialects: vec![Box::new(PostgreSqlDialect {}), Box::new(GenericDialect {})],
|
||||
options: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_json_ops_without_colon() {
|
||||
use self::JsonOperator;
|
||||
let binary_ops = &[
|
||||
("->", JsonOperator::Arrow, all_dialects()),
|
||||
("->>", JsonOperator::LongArrow, all_dialects()),
|
||||
("#>", JsonOperator::HashArrow, pg_and_generic()),
|
||||
("#>>", JsonOperator::HashLongArrow, pg_and_generic()),
|
||||
("@>", JsonOperator::AtArrow, all_dialects()),
|
||||
("<@", JsonOperator::ArrowAt, all_dialects()),
|
||||
("#-", JsonOperator::HashMinus, pg_and_generic()),
|
||||
("@?", JsonOperator::AtQuestion, all_dialects()),
|
||||
("@@", JsonOperator::AtAt, all_dialects()),
|
||||
];
|
||||
|
||||
for (str_op, op, dialects) in binary_ops {
|
||||
let select = dialects.verified_only_select(&format!("SELECT a {} b", &str_op));
|
||||
assert_eq!(
|
||||
SelectItem::UnnamedExpr(Expr::JsonAccess {
|
||||
left: Box::new(Expr::Identifier(Ident::new("a"))),
|
||||
operator: *op,
|
||||
right: Box::new(Expr::Identifier(Ident::new("b"))),
|
||||
}),
|
||||
select.projection[0]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_is_null() {
|
||||
use self::Expr::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue