Skip to content

[CALCITE-6537] Add syntax to allow non-aggregated rows to be used in GROUPING SETS - #5208

Open
xuzifu666 wants to merge 3 commits into
apache:mainfrom
xuzifu666:calcite-6537
Open

xuzifu666 wants to merge 3 commits into
apache:mainfrom
xuzifu666:calcite-6537

Conversation

@xuzifu666

Copy link
Copy Markdown
Member

# End agg.iq

# [CALCITE-6537] Add syntax to allow non-aggregated rows to be used in GROUPING SETS
# non-aggregated (detail) rows. Requires LENIENT conformance.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Since this is not standard SQL and is not supported by mainstream databases, it was converted to equivalent PostgreSQL syntax for verification; the results matched expectations: https://onecompiler.com/postgresql/44yz6y5r4

*
* @see org.apache.calcite.sql.validate.SqlConformance#isGroupingSetsStarAllowed()
*/
class GroupingSetsStarTest {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If these tests duplicate the quidem tests, they are not necessary

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes you are right, I had removed the GroupingSetsStarTest.


# End agg.iq

# [CALCITE-6537] Add syntax to allow non-aggregated rows to be used in GROUPING SETS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the parser uses a stack for grouping star, so it seems to support nested * calls. Are there unit tests for these cases?

We should either have unit tests for the full language supported, or support a more restricted form of the language.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Make sensen, I chose the restricted form. The parser is unchanged (the stack is still needed for grouping constructs nested in GROUPING SETS, e.g. GROUPING SETS (ROLLUP (deptno, *))), but the validator now only expands * in the well-defined positions of the syntax: a complete grouping set (GROUPING SETS (*)), an element of a grouping set (GROUPING SETS ((deptno), (*))), or an argument of ROLLUP/CUBE (ROLLUP (deptno, *)), including the GROUP BY DISTINCT wrapper. A star nested inside other expressions, say GROUPING SETS (ABS(*)), parses but is not expanded, so validation fails with "Unknown identifier ''", and top-level GROUP BY * remains a parse error.

@xuzifu666

Copy link
Copy Markdown
Member Author

Thank you for the review and so sorry, I saw this comment a bit late @mihaibudiu .
I have indeed made the relevant changes based on the suggestion, opting to implement a restriction to refine the solution.

@sonarqubecloud

Copy link
Copy Markdown

@mihaibudiu mihaibudiu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks fine, but it's subtle.

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.

2 participants