-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
olivrlee
wants to merge
3
commits into
apache:main
Choose a base branch
from
olivrlee:CALCITE-6035/unparse_within_group
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1294,6 +1294,19 @@ private static String toSql(RelNode root, SqlDialect dialect, | |
.withPostgresql().ok(expectedPostgresql); | ||
} | ||
|
||
@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 " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
+ "(ORDER BY product_class_id NULLS LAST)\n" | ||
+ "FROM foodmart.product"; | ||
final SqlParser.Config parserConfig = | ||
olivrlee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
BigQuerySqlDialect.DEFAULT.configureParser(SqlParser.config()); | ||
final Sql sql = fixture() | ||
.withBigQuery().withLibrary(SqlLibrary.BIG_QUERY).parserConfig(parserConfig); | ||
sql.withSql(query).ok(expected); | ||
} | ||
|
||
/** Test case for | ||
* <a href="https://issues.apache.org/jira/browse/CALCITE-2722">[CALCITE-2722] | ||
* SqlImplementor createLeftCall method throws StackOverflowError</a>. */ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 (yourinput_2
from that comment), do you know if this would break?There was a problem hiding this comment.
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