@@ -1583,7 +1583,7 @@ SelectBody SetOperationList() #SetOperationList: {
15831583{
15841584 (("(" select=SelectBody() ")" { bracket=true;} )
15851585 | ( select=PlainSelect() | select=Values() ) { bracket=false;} ) {selects.add(select);brackets.add(bracket); }
1586- (
1586+ ( LOOKAHEAD(2)
15871587 ((<K_UNION> { UnionOp union = new UnionOp();linkAST(union,jjtThis);operations.add(union); } [ <K_ALL> { union.setAll(true); } | <K_DISTINCT> { union.setDistinct(true); } ])
15881588 | <K_INTERSECT> { operations.add(new IntersectOp()); }
15891589 | <K_MINUS> { operations.add(new MinusOp()); }
@@ -1618,23 +1618,33 @@ SelectBody SetOperationList() #SetOperationList: {
16181618 }
16191619}
16201620
1621- SelectBody SetOperationListWithoutIntialSelect(SelectBody _select, boolean _bracket ) #SetOperationList:
1621+ SelectBody SetOperationListWithoutIntialSelect(FromItem fromItem ) #SetOperationList:
16221622{
16231623 SetOperationList list = new SetOperationList();
16241624 List<OrderByElement> orderByElements = null;
16251625 Limit limit = null;
16261626 Offset offset = null;
16271627 Fetch fetch = null;
1628- SelectBody select = _select ;
1628+ SelectBody select;
16291629 List<SelectBody> selects = new ArrayList<SelectBody>();
16301630 List<SetOperation> operations = new ArrayList<SetOperation>();
16311631 List<Boolean> brackets = new ArrayList<Boolean>();
1632- boolean bracket = _bracket ;
1632+ boolean bracket = false ;
16331633}
16341634{
16351635 {
1636+ while (fromItem instanceof ParenthesisFromItem) {
1637+ fromItem = ((ParenthesisFromItem)fromItem).getFromItem();
1638+ }
1639+
1640+ if (fromItem instanceof SubSelect) {
1641+ select = ((SubSelect)fromItem).getSelectBody();
1642+ } else {
1643+ throw new IllegalArgumentException("this type of set operation is not allowed");
1644+ }
1645+
16361646 selects.add(select);
1637- brackets.add(bracket );
1647+ brackets.add(true );
16381648 }
16391649 ( LOOKAHEAD(2)
16401650 ((<K_UNION> { UnionOp union = new UnionOp();linkAST(union,jjtThis);operations.add(union); } [ <K_ALL> { union.setAll(true); } | <K_DISTINCT> { union.setDistinct(true); } ])
@@ -2010,15 +2020,15 @@ FromItem FromItem():
20102020 |
20112021 fromItem=SubSelect()
20122022 )
2023+ [ selectBody = SetOperationListWithoutIntialSelect(fromItem)
2024+ {
2025+ if (!(selectBody instanceof PlainSelect)) {
2026+ fromItem = new SubSelect().withSelectBody(selectBody);
2027+ }
2028+ }
2029+ ]
20132030 ")"
20142031 [ LOOKAHEAD(2) unpivot=UnPivot() { fromItem.setUnPivot(unpivot); } ]
2015- [ LOOKAHEAD(2) selectBody = SetOperationListWithoutIntialSelect(((SubSelect)fromItem).getSelectBody(), true)
2016- {
2017- if (!(selectBody instanceof PlainSelect)) {
2018- fromItem = new SubSelect().withSelectBody(selectBody);
2019- }
2020- }
2021- ]
20222032 )
20232033 |
20242034 LOOKAHEAD(TableFunction())
0 commit comments