-
Notifications
You must be signed in to change notification settings - Fork 685
Support IN UNNEST(expression)
#426
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
Conversation
Pull Request Test Coverage Report for Build 1913841843
💛 - Coveralls |
alamb
left a comment
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.
I apologize for the late review, I have been away for the last week. Thank you for the contribution @komukomo
| subquery: Box<Query>, | ||
| negated: bool, | ||
| }, | ||
| /// `[ NOT ] IN UNNEST(array_expression)` |
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.
I was going to suggest making this somewhat more general with any expr (rather than specific for UNEST function) like:
/// [NOT] IN <expr>
InExpr {
expr: Box<Expr>,
in_expr: Box<Expr>,
negated: bool
}However, I see that https://cloud.google.com/bigquery/docs/reference/standard-sql/operators#in_operators treats it as a special case so I think it would be ok to do here as well.
Actually, looking more deeply, it seems like UNNEST actually supports with offset as well
https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#unnest_operator
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.
Thank you for your valuable review.
As you said, it seems to be treated as a special case and any other functions can't used, so I did like this.
Actually, looking more deeply, it seems like UNNEST actually supports with offset as well
I did not know about with offset, thank you.
However, WITH OFFSET seems to be available when UNNEST returns a table.
In the case of IN UNNSET(array_expression), WITH OFFSET cannot be used because this IN UNNEST(array_expression) is a syntax sugar of subquery:
IN (SELECT element FROM UNNEST(array_expression) AS element).
✅ SELECT * FROM UNNEST(ARRAY[1,2,3]) WITH OFFSET
✅ SELECT 1 IN UNNEST(ARRAY[1,2,3])
❌ SELECT 1 IN UNNEST(ARRAY[1,2,3]) WITH OFFSET
So, if we support with offset, I think it is better to separate it from this PR, because the implementation and testing will be completely different. (I will try it in the future, if possible).
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, if we support with offset, I think it is better to separate it from this PR,
I agree -- that makes sense. If anyone needs WITH OFFSET support it can be added as a follow on 👍
| } | ||
|
|
||
| #[test] | ||
| fn parse_in_unnest() { |
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.
Can you please also add a test for NOT IN UNNEST as well?
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.
Thanks! I will fix it!
|
@alamb I fixed it! |
|
Thanks again @komukomo |
This PR adds support
IN UNNEST(array_expression)for BigQuery.https://cloud.google.com/bigquery/docs/reference/standard-sql/operators#in_operators