EthanVieira commented on code in PR #2586:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2586#discussion_r4142543875
##########
src/parser/mod.rs:
##########
@@ -4456,24 +4462,34 @@ impl<'a> Parser<'a> {
});
}
self.expect_token(&Token::LParen)?;
- let in_op = match self.maybe_parse(|p| p.parse_query())? {
- Some(subquery) => Expr::InSubquery {
- expr: Box::new(expr),
- subquery,
- negated,
- },
- None => Expr::InList {
- expr: Box::new(expr),
- list: if self.dialect.supports_in_empty_list() {
- self.parse_comma_separated0(Parser::parse_expr,
Token::RParen)?
- } else {
- self.parse_comma_separated(Parser::parse_expr)?
- },
- negated,
- },
+ // A leading query is the whole subquery only when `)` follows it,
+ // otherwise it is the first item of a list, as in `IN ((SELECT 1),
2)`.
+ let start = self.index;
+ if !self.failed_in_subquery_positions.contains(&start) {
+ if let Some(subquery) = self.maybe_parse(|p| {
+ let subquery = p.parse_query()?;
+ p.expect_token(&Token::RParen)?;
Review Comment:
It looks like we will discard the error for an incorrect subquery and always
report it as a failed list. I think the diagnostics could be improved here in
certain scenarios.
For example:
`SELECT * FROM t WHERE x IN (SELECT y FROM u` would report a missing `)` at
`y` when it should report a missing `)` at the end of the line.
We could store a missing `)` error for the subquery and then if the list
interpretation also fails, report the clearer error.
Maybe a heuristic like:
1. If parsing the `SELECT` query itself fails, there’s no saved
closing-parenthesis error. The list parser’s error is reported.
2. If the query parses but its required `)` is missing, the parser saves
that error.
3. If the list interpretation succeeds, the saved error is ignored.
4. If the list also fails, the parser reports the saved `)` error, except
that a recursion-limit error always takes priority.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]