Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement GROUP BY () without columns #1218

Merged
merged 4 commits into from
Jun 3, 2021

Conversation

manticore-projects
Copy link
Contributor

CLEAN PR against master with minimal change set.

@coveralls
Copy link

coveralls commented May 28, 2021

Coverage Status

Coverage increased (+0.04%) to 88.718% when pulling c70195e on manticore-projects:GroupByWithoutColumns into 7c21242 on JSQLParser:master.

@wumpz
Copy link
Member

wumpz commented May 31, 2021

Which database does support this? Whats the meaning of this? A group by that does nothing?

@manticore-projects
Copy link
Contributor Author

Fixes Issue #1176.

I did not want to believe it myself, but it is supported by Postgres and H2. I published the valid samples.
To me, H2 and Postgres are the Holy Grail, so please accept.

Copy link
Member

@wumpz wumpz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one question.

@@ -2326,9 +2326,15 @@ GroupByElement GroupByColumnReferences():
}
{
<K_GROUP> <K_BY>
(
columnReference=SimpleExpression() {groupBy.addGroupByExpression(columnReference); }
( LOOKAHEAD(3) (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed a bit of logic in my latest commits. There is now a production SimpleExpressionList with and without brackets. Maybe we should change the group by expressions to an Expression List and simply put a SimpleExpressionList into it. This one should support both cases, but I am not sure about empty brackets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, will look into that tonight. You will have it before you wake up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delivered as requested:

<K_GROUP> <K_BY>
    (     LOOKAHEAD(2) (
              "(" ")" { groupBy.withUsingBrackets(true); }
          )
          | LOOKAHEAD(3) (
              "(" list = SimpleExpressionList(true)  ")" { groupBy.setGroupByExpressionList(list); }
          )
          |
          ( list = SimpleExpressionList(false) { groupBy.setGroupByExpressionList(list); }
          )
    |

Isn't it a beauty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, SimpleExpressionLists can't be empty and always expects at least 1 element in the Grammar Definition. I did not want to refactor this right now, but I think we should look for making it a normal list which could be empty.

@wumpz wumpz merged commit 999db01 into JSQLParser:master Jun 3, 2021
@manticore-projects manticore-projects deleted the GroupByWithoutColumns branch May 31, 2022 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants