Repository navigation
Add support for quantified comparison predicates (ALL/ANY/SOME) - #1459
Conversation
| let right = if self.is_query_ahead() { | ||
| // We have a subquery ahead (SELECT\WITH ...) need to rewind and | ||
| // use the parenthesis for parsing the subquery as an expression. | ||
| self.prev_token(); // SELECT |
There was a problem hiding this comment.
Would it make sense to call the self.prev_token() as part of the is_query_ahead() logic? Currently with the split it feels a bit disconnected that the method is abstracted but the caller here still has to know the details and manually rewind the token stream which seems like an arbitrary split of responsibility? So that if it works the same then the caller can only rely on the flag returned without knowing the details of how the check is done
There was a problem hiding this comment.
Yes, good idea, implemented in the new commit.
| // use the parenthesis for parsing the subquery as an expression. | ||
| self.prev_token(); // SELECT | ||
| self.prev_token(); // LParen | ||
| self.parse_subexpr(precedence)? |
There was a problem hiding this comment.
would it make sense to call self.try_parse_expr_sub_query() here already? it seems like it could let us avoid most of the if block here
There was a problem hiding this comment.
I tried to make that work in the new commit, but since we need to rewind the LParen first it got a bit messy
| } | ||
|
|
||
| /// Checks if the next keyword indicates a query, i.e. SELECT or WITH | ||
| pub fn is_query_ahead(&mut self) -> bool { |
There was a problem hiding this comment.
| pub fn is_query_ahead(&mut self) -> bool { | |
| fn peek_sub_query(&mut self) -> bool { |
also the function was made public, assuming that was unintentional?
There was a problem hiding this comment.
Fixed in new commit
| self.tokens | ||
| } | ||
|
|
||
| /// Checks if the next keyword indicates a query, i.e. SELECT or WITH |
There was a problem hiding this comment.
| /// Checks if the next keyword indicates a query, i.e. SELECT or WITH | |
| /// Returns true if the next keyword indicates a sub query, i.e. SELECT or WITH |
| left: Box<Expr>, | ||
| compare_op: BinaryOperator, | ||
| right: Box<Expr>, | ||
| // ANY and SOME are synonymous |
There was a problem hiding this comment.
Is there any one of the supported dialects supporting the SOME variant?
There was a problem hiding this comment.
There was a problem hiding this comment.
Ah cool! Can we include the link in the comment here as well? It could help later on in case someone comes across this and wonders the same
iffyio
left a comment
There was a problem hiding this comment.
Thanks @yoavcloud! Left a couple minor comment regarding doc links, other than that I think this looks good
| left: Box<Expr>, | ||
| compare_op: BinaryOperator, | ||
| right: Box<Expr>, | ||
| // ANY and SOME are synonymous |
There was a problem hiding this comment.
Ah cool! Can we include the link in the comment here as well? It could help later on in case someone comes across this and wonders the same
| regexp: bool, | ||
| }, | ||
| /// `ANY` operation e.g. `foo > ANY(bar)`, comparison operator is one of `[=, >, <, =>, =<, !=]` | ||
| /// https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#_8_9_quantified_comparison_predicate |
There was a problem hiding this comment.
I'm thinking we can link to snowflake instead? Since that's a supported dialect that has the subquery functionality. The current link doesnt seem to refer to any specific dialect so it could add confusion later on when trying to figure what features in the parser to maintain
| // use the parenthesis for parsing the subquery as an expression. | ||
| self.prev_token(); // SELECT | ||
| self.prev_token(); // LParen | ||
| self.parse_subexpr(precedence)? |
|
Pushed doc changes as recommended. |
alamb
left a comment
There was a problem hiding this comment.
🚀 -- thanks @iffyio and @yoavcloud
Pull Request Test Coverage Report for Build 11261716771Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
|
@alamb can you please trigger the workflow again? Fixed an issue with the URLs in the docs |
|
Thanks again @yoavcloud |
Allows comparisons against subquery results: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#_8_9_quantified_comparison_predicate
For example: