iffyio commented on code in PR #2202:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2202#discussion_r2781521555
##########
src/ast/mod.rs:
##########
@@ -4676,6 +4676,19 @@ pub enum Statement {
/// Additional `WITH` options for RAISERROR.
options: Vec<RaisErrorOption>,
},
+ /// Throw (MSSQL)
+ /// ```sql
+ /// THROW [ error_number, message, state ]
+ /// ```
+ /// See
<https://learn.microsoft.com/en-us/sql/t-sql/language-elements/throw-transact-sql>
+ Throw {
+ /// Error number expression.
+ error_number: Option<Box<Expr>>,
+ /// Error message expression.
+ message: Option<Box<Expr>>,
+ /// State expression.
+ state: Option<Box<Expr>>,
+ },
Review Comment:
we're slowly [moving
away](https://github.com/apache/datafusion-sqlparser-rs/issues/1204) from this
representation over to having all statements wrapped in a named struct. As a
result, can we do something like this instead?
```rust
struct Throw { ... }
Statement::Throw(Throw)
```
See the
[RAISE](https://github.com/guan404ming/datafusion-sqlparser-rs/blob/379434abc35038bc5e839c2b6571a02b2fe130d2/src/ast/mod.rs#L3459-L3460)
statement for an example
##########
src/parser/mod.rs:
##########
@@ -18260,6 +18261,31 @@ impl<'a> Parser<'a> {
}
}
+ /// Parse a MSSQL `THROW` statement
+ /// See
<https://learn.microsoft.com/en-us/sql/t-sql/language-elements/throw-transact-sql>
+ pub fn parse_throw(&mut self) -> Result<Statement, ParserError> {
+ // THROW with no arguments is a re-throw inside a CATCH block
+ if self.peek_token_ref().token == Token::SemiColon
+ || self.peek_token_ref().token == Token::EOF
+ {
+ return Ok(Statement::Throw {
+ error_number: None,
+ message: None,
+ state: None,
+ });
+ }
Review Comment:
```suggestion
```
I think we can skip this logic, it would be expected for the function to
return an error if the input is empty (per the previous comment about making
this function stand-alone)
##########
src/parser/mod.rs:
##########
@@ -670,6 +670,7 @@ impl<'a> Parser<'a> {
Keyword::RELEASE => self.parse_release(),
Keyword::COMMIT => self.parse_commit(),
Keyword::RAISERROR => Ok(self.parse_raiserror()?),
+ Keyword::THROW => Ok(self.parse_throw()?),
Review Comment:
```suggestion
Keyword::THROW => {
self.prev_token();
self.parse_throw().map(Into::into)
},
```
see
[RAISE](https://github.com/guan404ming/datafusion-sqlparser-rs/blob/379434abc35038bc5e839c2b6571a02b2fe130d2/src/parser/mod.rs#L618-L621)
for an example. we're moving to have the statement parsing functions return
the actual struct instead of a `Statement` enum variant. Also it would be ideal
that the `parse_throw` is a standalone function (able to parse a `THROW`
statement) so we rewind the token before invoking it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]