This is an automated email from the ASF dual-hosted git repository. github-bot pushed a commit to branch gh-readonly-queue/main/pr-2205-60abfecf66341f970894c03e696e862ef967e5a7 in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
commit fcc7bce1fa704125eaa9c033d3a022db7d661070 Author: Samyak Sarnayak <[email protected]> AuthorDate: Sat Feb 7 02:28:29 2026 +0530 Fix MAP literals parsing (#2205) --- src/parser/mod.rs | 3 ++- tests/sqlparser_common.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 585242a8..0b152f2b 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -3510,7 +3510,8 @@ impl<'a> Parser<'a> { /// /// [map]: https://duckdb.org/docs/sql/data_types/map.html#creating-maps fn parse_duckdb_map_field(&mut self) -> Result<MapEntry, ParserError> { - let key = self.parse_expr()?; + // Stop before `:` so it can act as a key/value separator + let key = self.parse_subexpr(self.dialect.prec_value(Precedence::Colon))?; self.expect_token(&Token::Colon)?; diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index b6b86704..3c32e627 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -13584,6 +13584,10 @@ fn test_map_syntax() { Expr::value(number(s)) } + fn null_expr() -> Expr { + Expr::Value((Value::Null).with_empty_span()) + } + check( "MAP {1: 10.0, 2: 20.0}", Expr::Map(Map { @@ -13648,6 +13652,55 @@ fn test_map_syntax() { ); check("MAP {}", Expr::Map(Map { entries: vec![] })); + + check( + "MAP {'a': 1, 'b': NULL}", + Expr::Map(Map { + entries: vec![ + MapEntry { + key: Box::new(Expr::Value( + (Value::SingleQuotedString("a".to_owned())).with_empty_span(), + )), + value: Box::new(number_expr("1")), + }, + MapEntry { + key: Box::new(Expr::Value( + (Value::SingleQuotedString("b".to_owned())).with_empty_span(), + )), + value: Box::new(null_expr()), + }, + ], + }), + ); + + check( + "MAP {1: [1, NULL, 3], 2: [4, NULL, 6], 3: [7, 8, 9]}", + Expr::Map(Map { + entries: vec![ + MapEntry { + key: Box::new(number_expr("1")), + value: Box::new(Expr::Array(Array { + elem: vec![number_expr("1"), null_expr(), number_expr("3")], + named: false, + })), + }, + MapEntry { + key: Box::new(number_expr("2")), + value: Box::new(Expr::Array(Array { + elem: vec![number_expr("4"), null_expr(), number_expr("6")], + named: false, + })), + }, + MapEntry { + key: Box::new(number_expr("3")), + value: Box::new(Expr::Array(Array { + elem: vec![number_expr("7"), number_expr("8"), number_expr("9")], + named: false, + })), + }, + ], + }), + ); } #[test] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
