Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

And parentheses after not operator if right is SQLQueryExpr #6291

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2306,25 +2306,25 @@ public boolean visit(SQLNotExpr x) {
print0(ucase ? "NOT " : "not ");
SQLExpr expr = x.getExpr();

boolean needQuote = false;
boolean needParentheses = false;

if (expr instanceof SQLBinaryOpExpr) {
SQLBinaryOpExpr binaryOpExpr = (SQLBinaryOpExpr) expr;
needQuote = binaryOpExpr.getOperator().isLogical();
needParentheses = binaryOpExpr.getOperator().isLogical();
if (binaryOpExpr.isParenthesized()) {
needQuote = false;
needParentheses = false;
}
} else if (expr instanceof SQLInListExpr || expr instanceof SQLNotExpr
|| expr instanceof SQLBinaryOpExprGroup) {
needQuote = true;
|| expr instanceof SQLBinaryOpExprGroup || expr instanceof SQLQueryExpr) {
needParentheses = true;
}

if (needQuote) {
if (needParentheses) {
print('(');
}
printExpr(expr, parameterized);

if (needQuote) {
if (needParentheses) {
print(')');
}

Expand Down
27 changes: 27 additions & 0 deletions core/src/test/resources/bvt/parser/odps/0.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
select CASE
WHEN UPPER(a) = 'a'
AND (SELECT b FROM UNNEST() ORDER BY c DESC LIMIT 1) = 'b'
AND NOT (SELECT d FROM UNNEST(e) ORDER BY f DESC LIMIT 1)
THEN 'IS'
ELSE 'OTHERS'
END from g
--------------------
SELECT CASE
WHEN UPPER(a) = 'a'
AND (
SELECT b
FROM UNNEST()
ORDER BY c DESC
LIMIT 1
) = 'b'
AND NOT (
SELECT d
FROM UNNEST(e)
ORDER BY f DESC
LIMIT 1
)
THEN 'IS'
ELSE 'OTHERS'
END
FROM g
------------------------------------------------------------------------------------------------------------------------
select struct(a.b, a.c as c, a.d) from a
--------------------
SELECT STRUCT(a.b, a.c AS c, a.d)
Expand Down
Loading