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 {
186186 void visit (AllTableColumns allTableColumns );
187187
188188 void visit (AllValue allValue );
189+
190+ void visit (IsDistinctExpression isDistinctExpression );
189191}
Original file line number Diff line number Diff line change @@ -504,6 +504,11 @@ public void visit(AllTableColumns allTableColumns) {
504504 public void visit (AllValue allValue ) {
505505 }
506506
507+ @ Override
508+ public void visit (IsDistinctExpression isDistinctExpression ) {
509+ visitBinaryExpression (isDistinctExpression );
510+ }
511+
507512 @ Override
508513 public void visit (SelectExpressionItem selectExpressionItem ) {
509514 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) {
576576
577577 }
578578
579+ @ Override
580+ public void visit (IsDistinctExpression isDistinctExpression ) {
581+ visitBinaryExpression (isDistinctExpression );
582+ }
583+
579584 @ Override
580585 public void visit (SelectExpressionItem item ) {
581586 item .getExpression ().accept (this );
Original file line number Diff line number Diff line change 5252import net .sf .jsqlparser .expression .operators .relational .RegExpMatchOperator ;
5353import net .sf .jsqlparser .expression .operators .relational .RegExpMySQLOperator ;
5454import net .sf .jsqlparser .expression .operators .relational .SimilarToExpression ;
55+ import net .sf .jsqlparser .expression .operators .relational .IsDistinctExpression ;
5556import net .sf .jsqlparser .expression .operators .relational .SupportsOldOracleJoinSyntax ;
5657import net .sf .jsqlparser .schema .Column ;
5758import net .sf .jsqlparser .schema .Table ;
@@ -988,4 +989,11 @@ public void visit(AllTableColumns allTableColumns) {
988989 public void visit (AllValue allValue ) {
989990 buffer .append (allValue );
990991 }
992+
993+ @ Override
994+ public void visit (IsDistinctExpression isDistinctExpression ) {
995+ buffer .append (isDistinctExpression .getLeftExpression () +
996+ isDistinctExpression .getStringExpression () +
997+ isDistinctExpression .getRightExpression ());
998+ }
991999}
Original file line number Diff line number Diff line change 4545import net .sf .jsqlparser .expression .operators .relational .RegExpMatchOperator ;
4646import net .sf .jsqlparser .expression .operators .relational .RegExpMySQLOperator ;
4747import net .sf .jsqlparser .expression .operators .relational .SimilarToExpression ;
48+ import net .sf .jsqlparser .expression .operators .relational .IsDistinctExpression ;
4849import net .sf .jsqlparser .expression .operators .relational .SupportsOldOracleJoinSyntax ;
4950import net .sf .jsqlparser .parser .feature .Feature ;
5051import net .sf .jsqlparser .schema .Column ;
@@ -579,4 +580,10 @@ public void visit(AllValue allValue) {
579580
580581 }
581582
583+ @ Override
584+ public void visit (IsDistinctExpression isDistinctExpression ) {
585+ isDistinctExpression .getLeftExpression ().accept (this );
586+ isDistinctExpression .getRightExpression ().accept (this );
587+ }
588+
582589}
Original file line number Diff line number Diff line change @@ -3149,6 +3149,7 @@ Expression SQLCondition():
31493149 | LOOKAHEAD(IsNullExpression()) result=IsNullExpression(left)
31503150 | LOOKAHEAD(IsBooleanExpression()) result=IsBooleanExpression(left)
31513151 | LOOKAHEAD(2) result=LikeExpression(left)
3152+ | LOOKAHEAD(IsDistinctExpression()) result=IsDistinctExpression(left)
31523153 | result=SimilarToExpression(left)
31533154 )) ]
31543155 )
@@ -3266,6 +3267,22 @@ Expression SimilarToExpression(Expression leftExpression) #SimilarToExpression:
32663267 }
32673268}
32683269
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+
32693286Expression IsNullExpression(Expression leftExpression):
32703287{
32713288 IsNullExpression result = new IsNullExpression();
Original file line number Diff line number Diff line change @@ -961,6 +961,18 @@ public void testDistinct() throws JSQLParserException {
961961 assertStatementCanBeDeparsedAs (select , statement );
962962 }
963963
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+
964976 @ Test
965977 public void testDistinctTop () throws JSQLParserException {
966978 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