mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-11-03 00:31:20 +00:00
Add overlay expr (#594)
* Add PLACING keyword to keywords list * Add high level overlay expr to Expr enum * Add parsing logic for overlay op * add ovleray and is not true/false/unknown tests
This commit is contained in:
parent
95fbb55f2c
commit
6f55dead53
4 changed files with 117 additions and 8 deletions
|
|
@ -348,6 +348,13 @@ pub enum Expr {
|
|||
trim_where: Option<TrimWhereField>,
|
||||
trim_what: Option<Box<Expr>>,
|
||||
},
|
||||
/// OVERLAY(<expr> PLACING <expr> FROM <expr>[ FOR <expr> ]
|
||||
Overlay {
|
||||
expr: Box<Expr>,
|
||||
overlay_what: Box<Expr>,
|
||||
overlay_from: Box<Expr>,
|
||||
overlay_for: Option<Box<Expr>>,
|
||||
},
|
||||
/// `expr COLLATE collation`
|
||||
Collate {
|
||||
expr: Box<Expr>,
|
||||
|
|
@ -639,8 +646,25 @@ impl fmt::Display for Expr {
|
|||
if let Some(from_part) = substring_from {
|
||||
write!(f, " FROM {}", from_part)?;
|
||||
}
|
||||
if let Some(from_part) = substring_for {
|
||||
write!(f, " FOR {}", from_part)?;
|
||||
if let Some(for_part) = substring_for {
|
||||
write!(f, " FOR {}", for_part)?;
|
||||
}
|
||||
|
||||
write!(f, ")")
|
||||
}
|
||||
Expr::Overlay {
|
||||
expr,
|
||||
overlay_what,
|
||||
overlay_from,
|
||||
overlay_for,
|
||||
} => {
|
||||
write!(
|
||||
f,
|
||||
"OVERLAY({} PLACING {} FROM {}",
|
||||
expr, overlay_what, overlay_from
|
||||
)?;
|
||||
if let Some(for_part) = overlay_for {
|
||||
write!(f, " FOR {}", for_part)?;
|
||||
}
|
||||
|
||||
write!(f, ")")
|
||||
|
|
|
|||
|
|
@ -382,6 +382,7 @@ define_keywords!(
|
|||
PERCENTILE_DISC,
|
||||
PERCENT_RANK,
|
||||
PERIOD,
|
||||
PLACING,
|
||||
PLANS,
|
||||
PORTION,
|
||||
POSITION,
|
||||
|
|
|
|||
|
|
@ -449,6 +449,7 @@ impl<'a> Parser<'a> {
|
|||
Keyword::EXTRACT => self.parse_extract_expr(),
|
||||
Keyword::POSITION => self.parse_position_expr(),
|
||||
Keyword::SUBSTRING => self.parse_substring_expr(),
|
||||
Keyword::OVERLAY => self.parse_overlay_expr(),
|
||||
Keyword::TRIM => self.parse_trim_expr(),
|
||||
Keyword::INTERVAL => self.parse_literal_interval(),
|
||||
Keyword::LISTAGG => self.parse_listagg_expr(),
|
||||
|
|
@ -884,6 +885,28 @@ impl<'a> Parser<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn parse_overlay_expr(&mut self) -> Result<Expr, ParserError> {
|
||||
// PARSE OVERLAY (EXPR PLACING EXPR FROM 1 [FOR 3])
|
||||
self.expect_token(&Token::LParen)?;
|
||||
let expr = self.parse_expr()?;
|
||||
self.expect_keyword(Keyword::PLACING)?;
|
||||
let what_expr = self.parse_expr()?;
|
||||
self.expect_keyword(Keyword::FROM)?;
|
||||
let from_expr = self.parse_expr()?;
|
||||
let mut for_expr = None;
|
||||
if self.parse_keyword(Keyword::FOR) {
|
||||
for_expr = Some(self.parse_expr()?);
|
||||
}
|
||||
self.expect_token(&Token::RParen)?;
|
||||
|
||||
Ok(Expr::Overlay {
|
||||
expr: Box::new(expr),
|
||||
overlay_what: Box::new(what_expr),
|
||||
overlay_from: Box::new(from_expr),
|
||||
overlay_for: for_expr.map(Box::new),
|
||||
})
|
||||
}
|
||||
|
||||
/// TRIM ([WHERE] ['text' FROM] 'text')\
|
||||
/// TRIM ('text')
|
||||
pub fn parse_trim_expr(&mut self) -> Result<Expr, ParserError> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue