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

[CALCITE-6035] Unparse 'WITHIN GROUP' for BigQuery dialect to match BigQuery documentation #3466

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

olivrlee
Copy link
Contributor

No description provided.

@olivrlee olivrlee marked this pull request as ready for review October 13, 2023 01:19
Copy link
Contributor

@tanclary tanclary left a comment

Choose a reason for hiding this comment

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

Looks good! Just left a couple questions

private static void unparseWithinGroup(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) {
assert call.operandCount() == 2;
call.operand(0).unparse(writer, 0, 0);
writer.keyword("OVER");
Copy link
Contributor

Choose a reason for hiding this comment

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

so I think you're more familiar with these clauses than me, is it guaranteed that the WITHIN GROUP translates to BQ's OVER in every case? are they really just synonyms for each other, I mean

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I detailed in this comment how Calcite currently only supports
select percentile_cont(0.5) within group (order by X)
so I want to say that for what is supported at this moment, it is sufficient

Copy link
Contributor

Choose a reason for hiding this comment

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

Ohhh ok. So if Calcite ended up supporting the partition by case (your input_2 from that comment), do you know if this would break?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Julian had a comment here about how we should approach the followup tickets
I think it won't work out of the box, there are things to figure out
We would still be parsing it as within_group in the parser, but want it to be handled differently in the validator.

questions to then consider: would we still use a SqlWithinGroupOperator? If yes, then that would be unparsed into "OVER" correctly. If not, this may have to change

@sonarcloud
Copy link

sonarcloud bot commented Oct 19, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

92.3% 92.3% Coverage
0.0% 0.0% Duplication

@Test void testPercentileContWithinGroupClauseBigQuery() {
final String query = "select percentile_cont(0.5) WITHIN GROUP (ORDER BY `product_class_id`)\n"
+ "from `foodmart`.`product`";
final String expected = "SELECT PERCENTILE_CONT(0.5) OVER "
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the PERCENTILE_CONT function for BigQuery must have two arguments. I think this expected query would probably fail since the column isn't passed to the function directly as an argument

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