-
Notifications
You must be signed in to change notification settings - Fork 613
Support parsing empty map literal syntax for DuckDB and Genric #1361
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
Changes from 1 commit
21cdef3
0763f52
5d81654
4479ecd
239ef53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2352,12 +2352,14 @@ impl<'a> Parser<'a> { | |
/// [map]: https://duckdb.org/docs/sql/data_types/map.html#creating-maps | ||
fn parse_duckdb_map_literal(&mut self) -> Result<Expr, ParserError> { | ||
self.expect_token(&Token::LBrace)?; | ||
|
||
let fields = self.parse_comma_separated(Self::parse_duckdb_map_field)?; | ||
|
||
self.expect_token(&Token::RBrace)?; | ||
|
||
Ok(Expr::Map(Map { entries: fields })) | ||
if self.peek_token().token == Token::RBrace { | ||
let _ = self.next_token(); // consume } | ||
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. Nit: ambiguous comments 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 followed the same style as parsing the array literal. Should I enhance them? 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. My bad, i interpreted wrongly. This look good. |
||
Ok(Expr::Map(Map { entries: vec![] })) | ||
} else { | ||
let fields = self.parse_comma_separated(Self::parse_duckdb_map_field)?; | ||
self.expect_token(&Token::RBrace)?; | ||
Ok(Expr::Map(Map { entries: fields })) | ||
} | ||
} | ||
|
||
/// Parse a field for a duckdb [map] | ||
|
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.
is it possible to switch to
let fields = self.parse_comma_separated0(Self::parse_duckdb_map_field)?;
instead? if so that would let us skip the if/else hereThere 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 don't think we can do it. It seems that
parse_comma_separated0
is for parentheses, but MAP uses braces.https://github.com/sqlparser-rs/sqlparser-rs/blob/d49acc67b13e1d68f2e6a25546161a68e165da4f/src/parser/mod.rs#L3487
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.
Ah i see, I'm thinking we could still reuse the logic (thinking its currently a bit odd that
parse_comma_separated0
is hardcoded to parenthesis whileparse_comma_separated
is token agnostic as it should be). Seems there's ony a couple of usages ofparse_comma_separated0
, we could change it to something likeparse_comma_separated0(|| {}, Token::RParen)
?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 addressed this in 0763f52 and 5d81654. I share the same logic for
brace
,parenthesis
, andbracket
. I think it looks better. Thanks.