Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,21 @@ public enum SortDirection {
private List<ExpressionList<Expression>> groupingSets = new ArrayList<>();
// postgres rollup is an ExpressionList
private boolean mysqlWithRollup = false;
private boolean distinct = false;

public boolean isUsingBrackets() {
return groupByExpressions.isUsingBrackets();
}

public boolean isDistinct() {
return distinct;
}

public GroupByElement setDistinct(boolean distinct) {
this.distinct = distinct;
return this;
}

public <T, S> T accept(GroupByVisitor<T> groupByVisitor, S context) {
return groupByVisitor.visit(this, context);
}
Expand Down Expand Up @@ -115,6 +125,9 @@ public String toString() {
public void appendTo(StringBuilder builder, Consumer<ExpressionList<?>> listRenderer,
Consumer<Expression> expressionRenderer) {
builder.append("GROUP BY ");
if (distinct) {
builder.append("DISTINCT ");
}
if (groupByExpressions != null) {
if (hasGroupBySortDirections()) {
appendOrderedExpressions(builder, expressionRenderer);
Expand Down
1 change: 1 addition & 0 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -10452,6 +10452,7 @@ GroupByElement GroupByColumnReferences():
}
{
<K_GROUP> <K_BY>
[ LOOKAHEAD(<K_DISTINCT>) <K_DISTINCT> { groupBy.setDistinct(true); } ]
(
LOOKAHEAD(2) (
<K_GROUPING> <K_SETS>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4792,6 +4792,13 @@ public void testGroupingSets3() throws JSQLParserException {
"SELECT COL_1 FROM TABLE_1 GROUP BY GROUPING SETS (COL_1, ())");
}

@Test
public void testGroupingSetsDistinctIssue2785() throws JSQLParserException {
PlainSelect select = (PlainSelect) assertSqlCanBeParsedAndDeparsed(
"SELECT 1 GROUP BY DISTINCT GROUPING SETS ((1), (1))");
assertTrue(select.getGroupBy().isDistinct());
}

@Test
public void testLongQualifiedNamesIssue763() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(
Expand Down