mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-18 11:49:45 +00:00
Support Map literal syntax for DuckDB and Generic (#1344)
This commit is contained in:
parent
71dc966586
commit
48ea5640a2
7 changed files with 219 additions and 0 deletions
|
@ -1078,6 +1078,9 @@ impl<'a> Parser<'a> {
|
|||
let expr = self.parse_subexpr(Self::PLUS_MINUS_PREC)?;
|
||||
Ok(Expr::Prior(Box::new(expr)))
|
||||
}
|
||||
Keyword::MAP if self.peek_token() == Token::LBrace && self.dialect.support_map_literal_syntax() => {
|
||||
self.parse_duckdb_map_literal()
|
||||
}
|
||||
// Here `w` is a word, check if it's a part of a multipart
|
||||
// identifier, a function call, or a simple identifier:
|
||||
_ => match self.peek_token().token {
|
||||
|
@ -2322,6 +2325,47 @@ impl<'a> Parser<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
/// DuckDB specific: Parse a duckdb [map]
|
||||
///
|
||||
/// Syntax:
|
||||
///
|
||||
/// ```sql
|
||||
/// Map {key1: value1[, ... ]}
|
||||
/// ```
|
||||
///
|
||||
/// [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 }))
|
||||
}
|
||||
|
||||
/// Parse a field for a duckdb [map]
|
||||
///
|
||||
/// Syntax
|
||||
///
|
||||
/// ```sql
|
||||
/// key: value
|
||||
/// ```
|
||||
///
|
||||
/// [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()?;
|
||||
|
||||
self.expect_token(&Token::Colon)?;
|
||||
|
||||
let value = self.parse_expr()?;
|
||||
|
||||
Ok(MapEntry {
|
||||
key: Box::new(key),
|
||||
value: Box::new(value),
|
||||
})
|
||||
}
|
||||
|
||||
/// Parse clickhouse [map]
|
||||
///
|
||||
/// Syntax
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue