File tree Expand file tree Collapse file tree 8 files changed +98
-0
lines changed
jjtree/net/sf/jsqlparser/parser
test/java/net/sf/jsqlparser/statement/select Expand file tree Collapse file tree 8 files changed +98
-0
lines changed Original file line number Diff line number Diff line change @@ -186,4 +186,6 @@ public interface ExpressionVisitor {
186
186
void visit (AllTableColumns allTableColumns );
187
187
188
188
void visit (AllValue allValue );
189
+
190
+ void visit (IsDistinctExpression isDistinctExpression );
189
191
}
Original file line number Diff line number Diff line change @@ -504,6 +504,11 @@ public void visit(AllTableColumns allTableColumns) {
504
504
public void visit (AllValue allValue ) {
505
505
}
506
506
507
+ @ Override
508
+ public void visit (IsDistinctExpression isDistinctExpression ) {
509
+ visitBinaryExpression (isDistinctExpression );
510
+ }
511
+
507
512
@ Override
508
513
public void visit (SelectExpressionItem selectExpressionItem ) {
509
514
selectExpressionItem .getExpression ().accept (this );
Original file line number Diff line number Diff line change
1
+ /*-
2
+ * #%L
3
+ * JSQLParser library
4
+ * %%
5
+ * Copyright (C) 2004 - 2019 JSQLParser
6
+ * %%
7
+ * Dual licensed under GNU LGPL 2.1 or Apache License 2.0
8
+ * #L%
9
+ */
10
+ package net .sf .jsqlparser .expression .operators .relational ;
11
+
12
+ import net .sf .jsqlparser .expression .BinaryExpression ;
13
+ import net .sf .jsqlparser .expression .ExpressionVisitor ;
14
+
15
+ public class IsDistinctExpression extends BinaryExpression {
16
+
17
+ private boolean not = false ;
18
+
19
+ public boolean isNot () {
20
+ return not ;
21
+ }
22
+
23
+ public void setNot (boolean b ) {
24
+ not = b ;
25
+ }
26
+
27
+ @ Override
28
+ public void accept (ExpressionVisitor expressionVisitor ) {
29
+ expressionVisitor .visit (this );
30
+ }
31
+
32
+ @ Override
33
+ public String getStringExpression () {
34
+ return " IS " + (isNot () ? "NOT " : "" ) + "DISTINCT FROM " ;
35
+ }
36
+
37
+ @ Override
38
+ public String toString () {
39
+ String retval = getLeftExpression () + getStringExpression () + getRightExpression ();
40
+ return retval ;
41
+ }
42
+ }
Original file line number Diff line number Diff line change @@ -576,6 +576,11 @@ public void visit(AllValue allValue) {
576
576
577
577
}
578
578
579
+ @ Override
580
+ public void visit (IsDistinctExpression isDistinctExpression ) {
581
+ visitBinaryExpression (isDistinctExpression );
582
+ }
583
+
579
584
@ Override
580
585
public void visit (SelectExpressionItem item ) {
581
586
item .getExpression ().accept (this );
Original file line number Diff line number Diff line change 52
52
import net .sf .jsqlparser .expression .operators .relational .RegExpMatchOperator ;
53
53
import net .sf .jsqlparser .expression .operators .relational .RegExpMySQLOperator ;
54
54
import net .sf .jsqlparser .expression .operators .relational .SimilarToExpression ;
55
+ import net .sf .jsqlparser .expression .operators .relational .IsDistinctExpression ;
55
56
import net .sf .jsqlparser .expression .operators .relational .SupportsOldOracleJoinSyntax ;
56
57
import net .sf .jsqlparser .schema .Column ;
57
58
import net .sf .jsqlparser .schema .Table ;
@@ -988,4 +989,11 @@ public void visit(AllTableColumns allTableColumns) {
988
989
public void visit (AllValue allValue ) {
989
990
buffer .append (allValue );
990
991
}
992
+
993
+ @ Override
994
+ public void visit (IsDistinctExpression isDistinctExpression ) {
995
+ buffer .append (isDistinctExpression .getLeftExpression () +
996
+ isDistinctExpression .getStringExpression () +
997
+ isDistinctExpression .getRightExpression ());
998
+ }
991
999
}
Original file line number Diff line number Diff line change 45
45
import net .sf .jsqlparser .expression .operators .relational .RegExpMatchOperator ;
46
46
import net .sf .jsqlparser .expression .operators .relational .RegExpMySQLOperator ;
47
47
import net .sf .jsqlparser .expression .operators .relational .SimilarToExpression ;
48
+ import net .sf .jsqlparser .expression .operators .relational .IsDistinctExpression ;
48
49
import net .sf .jsqlparser .expression .operators .relational .SupportsOldOracleJoinSyntax ;
49
50
import net .sf .jsqlparser .parser .feature .Feature ;
50
51
import net .sf .jsqlparser .schema .Column ;
@@ -579,4 +580,10 @@ public void visit(AllValue allValue) {
579
580
580
581
}
581
582
583
+ @ Override
584
+ public void visit (IsDistinctExpression isDistinctExpression ) {
585
+ isDistinctExpression .getLeftExpression ().accept (this );
586
+ isDistinctExpression .getRightExpression ().accept (this );
587
+ }
588
+
582
589
}
Original file line number Diff line number Diff line change @@ -3149,6 +3149,7 @@ Expression SQLCondition():
3149
3149
| LOOKAHEAD(IsNullExpression()) result=IsNullExpression(left)
3150
3150
| LOOKAHEAD(IsBooleanExpression()) result=IsBooleanExpression(left)
3151
3151
| LOOKAHEAD(2) result=LikeExpression(left)
3152
+ | LOOKAHEAD(IsDistinctExpression()) result=IsDistinctExpression(left)
3152
3153
| result=SimilarToExpression(left)
3153
3154
)) ]
3154
3155
)
@@ -3266,6 +3267,22 @@ Expression SimilarToExpression(Expression leftExpression) #SimilarToExpression:
3266
3267
}
3267
3268
}
3268
3269
3270
+ Expression IsDistinctExpression(Expression leftExpression) #IsDistinctExpression:
3271
+ {
3272
+ IsDistinctExpression result = new IsDistinctExpression();
3273
+ Expression rightExpression = null;
3274
+ }
3275
+ {
3276
+ <K_IS> [<K_NOT> { result.setNot(true); } ] <K_DISTINCT> <K_FROM>
3277
+ rightExpression=SimpleExpression()
3278
+ {
3279
+ result.setLeftExpression(leftExpression);
3280
+ result.setRightExpression(rightExpression);
3281
+ linkAST(result,jjtThis);
3282
+ return result;
3283
+ }
3284
+ }
3285
+
3269
3286
Expression IsNullExpression(Expression leftExpression):
3270
3287
{
3271
3288
IsNullExpression result = new IsNullExpression();
Original file line number Diff line number Diff line change @@ -961,6 +961,18 @@ public void testDistinct() throws JSQLParserException {
961
961
assertStatementCanBeDeparsedAs (select , statement );
962
962
}
963
963
964
+ @ Test
965
+ public void testIsDistinctFrom () throws JSQLParserException {
966
+ String stmt = "SELECT name FROM tbl WHERE name IS DISTINCT FROM foo" ;
967
+ assertSqlCanBeParsedAndDeparsed (stmt );
968
+ }
969
+
970
+ @ Test
971
+ public void testIsNotDistinctFrom () throws JSQLParserException {
972
+ String stmt = "SELECT name FROM tbl WHERE name IS NOT DISTINCT FROM foo" ;
973
+ assertSqlCanBeParsedAndDeparsed (stmt );
974
+ }
975
+
964
976
@ Test
965
977
public void testDistinctTop () throws JSQLParserException {
966
978
String statement = "SELECT DISTINCT TOP 5 myid, mycol FROM mytable WHERE mytable.col = 9" ;
You can’t perform that action at this time.
0 commit comments