mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-19 05:30:19 +00:00
feat: support SAFE_CAST for bigquery (#552)
Co-authored-by: togami2864 <yoshiaki.togami@plaid.co.jp>
This commit is contained in:
parent
2a04212e56
commit
e24951e080
4 changed files with 29 additions and 0 deletions
|
@ -426,6 +426,7 @@ impl<'a> Parser<'a> {
|
|||
Keyword::CASE => self.parse_case_expr(),
|
||||
Keyword::CAST => self.parse_cast_expr(),
|
||||
Keyword::TRY_CAST => self.parse_try_cast_expr(),
|
||||
Keyword::SAFE_CAST => self.parse_safe_cast_expr(),
|
||||
Keyword::EXISTS => self.parse_exists_expr(false),
|
||||
Keyword::EXTRACT => self.parse_extract_expr(),
|
||||
Keyword::POSITION => self.parse_position_expr(),
|
||||
|
@ -780,6 +781,19 @@ impl<'a> Parser<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
/// Parse a BigQuery SAFE_CAST function e.g. `SAFE_CAST(expr AS FLOAT64)`
|
||||
pub fn parse_safe_cast_expr(&mut self) -> Result<Expr, ParserError> {
|
||||
self.expect_token(&Token::LParen)?;
|
||||
let expr = self.parse_expr()?;
|
||||
self.expect_keyword(Keyword::AS)?;
|
||||
let data_type = self.parse_data_type()?;
|
||||
self.expect_token(&Token::RParen)?;
|
||||
Ok(Expr::SafeCast {
|
||||
expr: Box::new(expr),
|
||||
data_type,
|
||||
})
|
||||
}
|
||||
|
||||
/// Parse a SQL EXISTS expression e.g. `WHERE EXISTS(SELECT ...)`.
|
||||
pub fn parse_exists_expr(&mut self, negated: bool) -> Result<Expr, ParserError> {
|
||||
self.expect_token(&Token::LParen)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue