-
Notifications
You must be signed in to change notification settings - Fork 600
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
feat: Array parsing support #604
Conversation
The author of this PR, nanderstabel, is not an activated member of this organization on Codecov. |
The misc-check failed due to network failure, don't worry about that. |
rust/sqlparser/src/parser.rs
Outdated
/// Parse a comma-separated list of 1+ items accepted by `F` with uniform value types | ||
pub fn parse_comma_separated_uniform<T, F>(&mut self, mut f: F) -> Result<Vec<T>, ParserError> | ||
where | ||
F: FnMut(&mut Parser) -> Result<T, ParserError>, |
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.
You can leave type validation to the optimizer. Because you may be unable to determine the type of a very complex expression, e.g. ARRAY[1+2*3, 3.0]
could be valid as type LIST<Decimal>
.
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.
Ok I see, I was thinking too complicated. Will use parse_comma_separated
instead 👍
Empty row in the format of |
If I am running this test I'm getting parsererror though:
Error:
In a similar way for ARRAY currently |
Ok, so that's a bug.
SQLs as above are quite well-supported in PG. Fix it 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.
rest lgtm
rust/sqlparser/src/parser.rs
Outdated
pub fn parse_bracketed_exprs(&mut self) -> Result<Vec<Expr>, ParserError> { | ||
if self.consume_token(&Token::LBracket) { | ||
let exprs = self.parse_comma_separated(Parser::parse_expr)?; | ||
self.expect_token(&Token::RBracket)?; | ||
Ok(exprs) | ||
} else { | ||
self.expected("an array of expressions in brackets", self.peek_token()) | ||
} | ||
} | ||
|
||
pub fn parse_braced_exprs(&mut self) -> Result<Vec<Expr>, ParserError> { | ||
self.prev_token(); | ||
if self.consume_token(&Token::LBrace) { | ||
let exprs = self.parse_comma_separated(Parser::parse_expr)?; | ||
self.expect_token(&Token::RBrace)?; | ||
Ok(exprs) | ||
} else { | ||
self.expected("an array of expressions in braces", self.peek_token()) | ||
} | ||
} |
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.
These two functions are duplicated (as well as parse_parenthesized_exprs
).
pub fn parse_braced_exprs(&mut self) -> Result<Vec<Expr>, ParserError> {
parse_token_wrapped_exprs(self, &Token::LBrace, &Token::RBrace)
}
fn parse_token_wrapped_exprs(&mut self, left: &Token, right: &Token) -> Result<Vec<Expr>, ParserError> {
self.prev_token();
if self.consume_token(left) {
let exprs = self.parse_comma_separated(Parser::parse_expr)?;
self.expect_token(right)?;
Ok(exprs)
} else {
self.expected("an array of expressions in {} and {}", self.peek_token(), left, right)
}
}
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 decided to remove those duplicated functions completely (including parse_parenthesized_exprs
) and replaced them with parse_token_wrapped_exprs
.
…rse_token_wrapped_exprs(left, right) function
What's changed and what's your intention?
Draft pull request resolving adding support for ARRAY value expression parsing #516. Both the
ARRAY[1, 2, 3]
and{1, 2, 3}
syntax are supported.Expr
variant `Array(Vec) is added including display trait.parse_comma_separated_uniform
creates a vector ofExpr
with uniform value types.parse_bracketed_exprs
andparse_braced_exprs
similar to the alredy existingparse_parenthesized_exprs
function. I did also removeToken::RBracket
from theget_next_precedence()
function since it was messing with the nested parsing. As far as I could see it was not used anywhere else.Checklist