Skip to content

Commit b1fda6d

Browse files
lingo-xpwenshao
authored andcommitted
Support parse more variant cases.
1 parent 1121b30 commit b1fda6d

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

core/src/main/java/com/alibaba/druid/sql/ast/expr/SQLBinaryOperator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public enum SQLBinaryOperator {
9999
BooleanXor("XOR", 150),
100100
BooleanOr("OR", 160),
101101
Assignment(":=", 169),
102+
Blank("", 170),
102103

103104
PG_And("&&", 140),
104105
PG_ST_DISTANCE("<->", 20);

core/src/main/java/com/alibaba/druid/sql/parser/SQLExprParser.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3532,6 +3532,9 @@ public SQLExpr andRest(SQLExpr expr) {
35323532
SQLBinaryOperator operator = andRestGetAndOperator();
35333533

35343534
expr = new SQLBinaryOpExpr(expr, operator, rightExp, dbType);
3535+
} else if (token == VARIANT) {
3536+
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Blank, new SQLVariantRefExpr(lexer.stringVal()), dbType);
3537+
lexer.nextToken();
35353538
} else {
35363539
break;
35373540
}
@@ -3977,6 +3980,11 @@ public SQLExpr relationalRest(SQLExpr expr) {
39773980
return expr;
39783981
}
39793982
break;
3983+
case VARIANT:
3984+
rightExp = new SQLVariantRefExpr(lexer.stringVal);
3985+
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Blank, rightExp, dbType);
3986+
lexer.nextToken();
3987+
return expr;
39803988
default:
39813989
return expr;
39823990
}

core/src/main/java/com/alibaba/druid/sql/parser/SQLSelectParser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ public void parseWhere(SQLSelectQueryBlock queryBlock) {
756756
case BANGEQ:
757757
case LIKE:
758758
case NOT:
759+
case VARIANT:
759760
where = this.exprParser.relationalRest(where);
760761
break;
761762
default:

core/src/main/java/com/alibaba/druid/sql/visitor/SQLASTOutputVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ && isPrettyFormat()
10481048
&& ((SQLIdentifierExpr) right).getName().equalsIgnoreCase("NOTFOUND")) {
10491049
printOpSpace = false;
10501050
}
1051-
if (printOpSpace) {
1051+
if (printOpSpace && operator != SQLBinaryOperator.Blank) {
10521052
print(' ');
10531053
}
10541054
}

core/src/test/resources/bvt/parser/clickhouse/0.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
select c from b where c=1 ${if(len(a)=0,'and 1=1',"and a>0")} ${if(len(a)=0,'and 1=1',"and a>0")}
2+
--------------------
3+
SELECT c
4+
FROM b
5+
WHERE c = 1 ${if(len(a)=0,'and 1=1',"and a>0")} ${if(len(a)=0,'and 1=1',"and a>0")}
6+
------------------------------------------------------------------------------------------------------------------------
7+
select ${if(len(a)=0,' 1=1 ',"c")}, ${if(len(a)=0,' 1=1 ',"c")} from b
8+
--------------------
9+
SELECT ${if(len(a)=0,' 1=1 ',"c")}, ${if(len(a)=0,' 1=1 ',"c")}
10+
FROM b
11+
------------------------------------------------------------------------------------------------------------------------
112
--test
213
select a from b
314
--------------------

0 commit comments

Comments
 (0)