File tree Expand file tree Collapse file tree
java/net/sf/jsqlparser/statement/select
jjtree/net/sf/jsqlparser/parser
test/java/net/sf/jsqlparser/statement/select Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,11 +33,21 @@ public enum SortDirection {
3333 private List <ExpressionList <Expression >> groupingSets = new ArrayList <>();
3434 // postgres rollup is an ExpressionList
3535 private boolean mysqlWithRollup = false ;
36+ private boolean distinct = false ;
3637
3738 public boolean isUsingBrackets () {
3839 return groupByExpressions .isUsingBrackets ();
3940 }
4041
42+ public boolean isDistinct () {
43+ return distinct ;
44+ }
45+
46+ public GroupByElement setDistinct (boolean distinct ) {
47+ this .distinct = distinct ;
48+ return this ;
49+ }
50+
4151 public <T , S > T accept (GroupByVisitor <T > groupByVisitor , S context ) {
4252 return groupByVisitor .visit (this , context );
4353 }
@@ -115,6 +125,9 @@ public String toString() {
115125 public void appendTo (StringBuilder builder , Consumer <ExpressionList <?>> listRenderer ,
116126 Consumer <Expression > expressionRenderer ) {
117127 builder .append ("GROUP BY " );
128+ if (distinct ) {
129+ builder .append ("DISTINCT " );
130+ }
118131 if (groupByExpressions != null ) {
119132 if (hasGroupBySortDirections ()) {
120133 appendOrderedExpressions (builder , expressionRenderer );
Original file line number Diff line number Diff line change @@ -10452,6 +10452,7 @@ GroupByElement GroupByColumnReferences():
1045210452}
1045310453{
1045410454 <K_GROUP> <K_BY>
10455+ [ LOOKAHEAD(<K_DISTINCT>) <K_DISTINCT> { groupBy.setDistinct(true); } ]
1045510456 (
1045610457 LOOKAHEAD(2) (
1045710458 <K_GROUPING> <K_SETS>
Original file line number Diff line number Diff line change @@ -4792,6 +4792,13 @@ public void testGroupingSets3() throws JSQLParserException {
47924792 "SELECT COL_1 FROM TABLE_1 GROUP BY GROUPING SETS (COL_1, ())" );
47934793 }
47944794
4795+ @ Test
4796+ public void testGroupingSetsDistinctIssue2785 () throws JSQLParserException {
4797+ PlainSelect select = (PlainSelect ) assertSqlCanBeParsedAndDeparsed (
4798+ "SELECT 1 GROUP BY DISTINCT GROUPING SETS ((1), (1))" );
4799+ assertTrue (select .getGroupBy ().isDistinct ());
4800+ }
4801+
47954802 @ Test
47964803 public void testLongQualifiedNamesIssue763 () throws JSQLParserException {
47974804 assertSqlCanBeParsedAndDeparsed (
You can’t perform that action at this time.
0 commit comments