Skip to content

Commit 4492e74

Browse files
SunandaS76sunanda-vs
andauthored
added support for minus all; except all; intersect all; (#2081)
Co-authored-by: sunanda-vs <22m2107@iitb.ac.in>
1 parent b366f2b commit 4492e74

File tree

4 files changed

+131
-4
lines changed

4 files changed

+131
-4
lines changed

src/main/java/net/sf/jsqlparser/statement/select/ExceptOp.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,47 @@
1313

1414
public class ExceptOp extends SetOperation {
1515

16+
private boolean distinct;
17+
private boolean all;
18+
1619
public ExceptOp() {
1720
super(SetOperationType.EXCEPT);
1821
}
22+
23+
public boolean isAll() {
24+
return all;
25+
}
26+
27+
public void setAll(boolean all) {
28+
this.all = all;
29+
}
30+
31+
public boolean isDistinct() {
32+
return distinct;
33+
}
34+
35+
public void setDistinct(boolean distinct) {
36+
this.distinct = distinct;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
String allDistinct = "";
42+
if (isAll()) {
43+
allDistinct = " ALL";
44+
} else if (isDistinct()) {
45+
allDistinct = " DISTINCT";
46+
}
47+
return super.toString() + allDistinct;
48+
}
49+
50+
public ExceptOp withDistinct(boolean distinct) {
51+
this.setDistinct(distinct);
52+
return this;
53+
}
54+
55+
public ExceptOp withAll(boolean all) {
56+
this.setAll(all);
57+
return this;
58+
}
1959
}

src/main/java/net/sf/jsqlparser/statement/select/IntersectOp.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,46 @@
1313

1414
public class IntersectOp extends SetOperation {
1515

16+
private boolean distinct;
17+
private boolean all;
18+
1619
public IntersectOp() {
1720
super(SetOperationType.INTERSECT);
1821
}
22+
public boolean isAll() {
23+
return all;
24+
}
25+
26+
public void setAll(boolean all) {
27+
this.all = all;
28+
}
29+
30+
public boolean isDistinct() {
31+
return distinct;
32+
}
33+
34+
public void setDistinct(boolean distinct) {
35+
this.distinct = distinct;
36+
}
37+
38+
@Override
39+
public String toString() {
40+
String allDistinct = "";
41+
if (isAll()) {
42+
allDistinct = " ALL";
43+
} else if (isDistinct()) {
44+
allDistinct = " DISTINCT";
45+
}
46+
return super.toString() + allDistinct;
47+
}
48+
49+
public IntersectOp withDistinct(boolean distinct) {
50+
this.setDistinct(distinct);
51+
return this;
52+
}
53+
54+
public IntersectOp withAll(boolean all) {
55+
this.setAll(all);
56+
return this;
57+
}
1958
}

src/main/java/net/sf/jsqlparser/statement/select/MinusOp.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,46 @@
1212
import net.sf.jsqlparser.statement.select.SetOperationList.SetOperationType;
1313

1414
public class MinusOp extends SetOperation {
15-
15+
private boolean distinct;
16+
private boolean all;
17+
1618
public MinusOp() {
1719
super(SetOperationType.MINUS);
1820
}
21+
public boolean isAll() {
22+
return all;
23+
}
24+
25+
public void setAll(boolean all) {
26+
this.all = all;
27+
}
28+
29+
public boolean isDistinct() {
30+
return distinct;
31+
}
32+
33+
public void setDistinct(boolean distinct) {
34+
this.distinct = distinct;
35+
}
36+
37+
@Override
38+
public String toString() {
39+
String allDistinct = "";
40+
if (isAll()) {
41+
allDistinct = " ALL";
42+
} else if (isDistinct()) {
43+
allDistinct = " DISTINCT";
44+
}
45+
return super.toString() + allDistinct;
46+
}
47+
48+
public MinusOp withDistinct(boolean distinct) {
49+
this.setDistinct(distinct);
50+
return this;
51+
}
52+
53+
public MinusOp withAll(boolean all) {
54+
this.setAll(all);
55+
return this;
56+
}
1957
}

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3043,11 +3043,21 @@ Select SetOperationList(Select select) #SetOperationList: {
30433043
[ <K_ALL> { union.setAll(true); } | <K_DISTINCT> { union.setDistinct(true); } ]
30443044
)
30453045
|
3046-
<K_INTERSECT> { operations.add(new IntersectOp()); }
3046+
(
3047+
<K_INTERSECT> { IntersectOp intersect = new IntersectOp(); linkAST(intersect,jjtThis); operations.add(intersect); }
3048+
[ <K_ALL> { intersect.setAll(true); } | <K_DISTINCT> { intersect.setDistinct(true); } ]
3049+
)
30473050
|
3048-
<K_MINUS> { operations.add(new MinusOp()); }
3051+
(
3052+
<K_MINUS> { MinusOp minus = new MinusOp(); linkAST(minus,jjtThis); operations.add(minus); }
3053+
[ <K_ALL> { minus.setAll(true); } | <K_DISTINCT> { minus.setDistinct(true); } ]
3054+
)
30493055
|
3050-
<K_EXCEPT> { operations.add(new ExceptOp()); }
3056+
(
3057+
<K_EXCEPT> { ExceptOp except = new ExceptOp(); linkAST(except,jjtThis); operations.add(except); }
3058+
[ <K_ALL> { except.setAll(true); } | <K_DISTINCT> { except.setDistinct(true); } ]
3059+
)
3060+
30513061
)
30523062

30533063
(

0 commit comments

Comments
 (0)