LucaCappelletti94 commented on code in PR #2424:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2424#discussion_r3926085154
##########
src/ast/mod.rs:
##########
@@ -196,6 +196,36 @@ where
DisplaySeparated { slice, sep: ", " }
}
+/// Returns true when the prefix operator `op` written directly before
`operand`
+/// would be tokenized as a single operator rather than as two.
+fn lexes_as_one_operator(op: &UnaryOperator, operand: &Expr) -> bool {
+ let Expr::UnaryOp { op: leading, .. } = operand else {
Review Comment:
Nested unary operator also reaches the output through a lower-precedence
parent.
I suggest you use a display-loop fuzzer to catch these errors during your
next review iteration, and consider also using a criterion benchmark to ensure
the performance do not fall.
##########
tests/sqlparser_postgres.rs:
##########
@@ -9684,6 +9684,40 @@ fn parse_right_deep_join_chain() {
pg().verified_stmt("SELECT * FROM t0 NATURAL JOIN t1 INNER JOIN t2 ON
true");
}
+#[test]
+fn parse_nested_pg_unary_ops() {
+ let select = pg().verified_only_select("SELECT @ @1");
+ assert_eq!(
+ SelectItem::UnnamedExpr(Expr::UnaryOp {
+ op: UnaryOperator::PGAbs,
+ expr: Box::new(Expr::UnaryOp {
+ op: UnaryOperator::PGAbs,
+ expr: Box::new(Expr::value(number("1"))),
+ }),
+ }),
+ select.projection[0]
+ );
+
+ let select = pg().verified_only_select("SELECT @@ 1");
+ assert_eq!(
+ SelectItem::UnnamedExpr(Expr::UnaryOp {
+ op: UnaryOperator::DoubleAt,
+ expr: Box::new(Expr::value(number("1"))),
+ }),
+ select.projection[0]
+ );
+
+ pg().verified_stmt("SELECT |/ |/1");
Review Comment:
Here is an example of why you should pin the lower-precedence operand case,
as before the source change it fails with `left: "SELECT ~ -a * 2"`, `right:
"SELECT ~-a * 2"`.
```suggestion
pg().verified_stmt("SELECT |/ |/1");
pg().verified_stmt("SELECT ~ -a * 2");
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]