iffyio commented on code in PR #1884:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1884#discussion_r2151944587


##########
src/ast/mod.rs:
##########
@@ -2982,6 +2982,74 @@ impl From<Set> for Statement {
     }
 }
 
+/// An exception representing exception handling with the `EXCEPTION` keyword.
+///
+/// Snowflake: 
<https://docs.snowflake.com/en/sql-reference/snowflake-scripting/exception>
+/// BigQuery: 
<https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#beginexceptionend>
+#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
+pub struct ExceptionClause {
+    /// When represents each `WHEN` case
+    pub when: Vec<ExceptionWhen>,
+    /// The exception that is being raised or the current exception being 
handled if `None`.
+    ///
+    /// Example
+    /// RAISE;
+    /// RAISE MY_EXCEPTION;
+    /// RAISE USING MESSAGE = "Some error";

Review Comment:
   Can we wrap this in a sql codeblock? Also I think it would be useful to show 
the example in the context of the exception when (i.e. illustrating the part of 
the statement does this property map to) vs a standalone statement (which is 
already documented elsewhere)



##########
src/ast/mod.rs:
##########
@@ -2982,6 +2982,74 @@ impl From<Set> for Statement {
     }
 }
 
+/// An exception representing exception handling with the `EXCEPTION` keyword.
+///
+/// Snowflake: 
<https://docs.snowflake.com/en/sql-reference/snowflake-scripting/exception>
+/// BigQuery: 
<https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#beginexceptionend>
+#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
+pub struct ExceptionClause {
+    /// When represents each `WHEN` case
+    pub when: Vec<ExceptionWhen>,
+    /// The exception that is being raised or the current exception being 
handled if `None`.
+    ///
+    /// Example
+    /// RAISE;
+    /// RAISE MY_EXCEPTION;
+    /// RAISE USING MESSAGE = "Some error";
+    ///
+    /// BigQuery: 
<https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#raise>
+    /// Snowflake: 
<https://docs.snowflake.com/en/sql-reference/snowflake-scripting/raise>
+    // pub raises: Option<Option<Ident>>,
+    pub raises: Option<Box<Statement>>,
+}
+
+impl Display for ExceptionClause {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, " EXCEPTION")?;
+        for w in &self.when {
+            write!(f, "{w}")?;
+        }
+
+        if let Some(raises) = &self.raises {
+            write!(f, " {raises};")?;
+        }
+
+        Ok(())
+    }
+}
+
+/// A representation of a `WHEN` arm with all the identifiers catched and the 
statements to execute
+/// for the arm.
+///
+/// Snowflake: 
<https://docs.snowflake.com/en/sql-reference/snowflake-scripting/exception>
+/// BigQuery: 
<https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#beginexceptionend>
+#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
+pub struct ExceptionWhen {
+    pub idents: Vec<Ident>,
+    pub statements: Vec<Statement>,
+}
+
+impl Display for ExceptionWhen {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(
+            f,
+            " WHEN {idents} THEN",

Review Comment:
   ```suggestion
               "WHEN {idents} THEN",
   ```
   display wise its better to have the display impl self contained (the caller 
should write the leading space when needed), that makes it easier to display 
the same struct in other contexts



##########
src/ast/mod.rs:
##########
@@ -3670,17 +3727,24 @@ pub enum Statement {
         /// END;
         /// ```
         statements: Vec<Statement>,
-        /// Statements of an exception clause.
+        /// Exception handling with exception clauses and raises.
         /// Example:
         /// ```sql
         /// BEGIN
         ///     SELECT 1;
-        /// EXCEPTION WHEN ERROR THEN
-        ///     SELECT 2;
-        ///     SELECT 3;
+        /// EXCEPTION
+        ///     WHEN EXCEPTION_1 THEN
+        ///         SELECT 2;
+        ///     WHEN EXCEPTION_2 OR EXCEPTION_3 THEN
+        ///         SELECT 3;
+        ///     WHEN OTHER THEN
+        ///         SELECT 4;
+        /// RAISE;

Review Comment:
   looking at snowflake and bigquery docs there doest seem to be a need for 
treat raise specially from what i can tell.
   
   snowflake: their example 
[here](https://docs.snowflake.com/en/developer-guide/snowflake-scripting/exceptions#raising-the-same-exception-again-in-an-exception-handler)
 shows raise as a regular statement in the statement list.
   
   bigquery: their 
[spec](https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#beginexceptionend)
 also only mentions a statement list.
   
   Also looking at this [example test 
case](https://github.com/apache/datafusion-sqlparser-rs/blob/4848e91bf3f9d2d2a1cb53cc898764abfa953d42/tests/sqlparser_snowflake.rs#L4097),
 its not clear to me where the `RAISE` statement applies to, and formatting 
wise looks different from whats in the snowflake doc like in the example above
   
   I dont think it matters too much in which context the raise statement 
applies or the exact behavior of the statement in those scenarios, thats more 
towards semantics.
   
   So that it seems to me that we should be able to leave as is in the previous 
behavior of treating `RAISE` as a regular statement. Was there an example sql  
that wasn't covered by that approach?



##########
src/ast/mod.rs:
##########
@@ -2982,6 +2982,74 @@ impl From<Set> for Statement {
     }
 }
 
+/// An exception representing exception handling with the `EXCEPTION` keyword.
+///
+/// Snowflake: 
<https://docs.snowflake.com/en/sql-reference/snowflake-scripting/exception>
+/// BigQuery: 
<https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#beginexceptionend>
+#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
+pub struct ExceptionClause {
+    /// When represents each `WHEN` case
+    pub when: Vec<ExceptionWhen>,
+    /// The exception that is being raised or the current exception being 
handled if `None`.
+    ///
+    /// Example
+    /// RAISE;
+    /// RAISE MY_EXCEPTION;
+    /// RAISE USING MESSAGE = "Some error";
+    ///
+    /// BigQuery: 
<https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#raise>
+    /// Snowflake: 
<https://docs.snowflake.com/en/sql-reference/snowflake-scripting/raise>
+    // pub raises: Option<Option<Ident>>,
+    pub raises: Option<Box<Statement>>,
+}
+
+impl Display for ExceptionClause {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, " EXCEPTION")?;

Review Comment:
   ```suggestion
           write!(f, "EXCEPTION")?;
   ```
   similar comment re display below



##########
src/ast/mod.rs:
##########
@@ -2982,6 +2982,74 @@ impl From<Set> for Statement {
     }
 }
 
+/// An exception representing exception handling with the `EXCEPTION` keyword.
+///
+/// Snowflake: 
<https://docs.snowflake.com/en/sql-reference/snowflake-scripting/exception>
+/// BigQuery: 
<https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#beginexceptionend>
+#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
+pub struct ExceptionClause {
+    /// When represents each `WHEN` case
+    pub when: Vec<ExceptionWhen>,
+    /// The exception that is being raised or the current exception being 
handled if `None`.
+    ///
+    /// Example
+    /// RAISE;
+    /// RAISE MY_EXCEPTION;
+    /// RAISE USING MESSAGE = "Some error";
+    ///
+    /// BigQuery: 
<https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#raise>
+    /// Snowflake: 
<https://docs.snowflake.com/en/sql-reference/snowflake-scripting/raise>
+    // pub raises: Option<Option<Ident>>,
+    pub raises: Option<Box<Statement>>,

Review Comment:
   hmm actually would it make more sense to represent this as a `RaiseStmt` 
instead of an opaque `Statement`?



##########
src/ast/mod.rs:
##########
@@ -2982,6 +2982,74 @@ impl From<Set> for Statement {
     }
 }
 
+/// An exception representing exception handling with the `EXCEPTION` keyword.
+///
+/// Snowflake: 
<https://docs.snowflake.com/en/sql-reference/snowflake-scripting/exception>
+/// BigQuery: 
<https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#beginexceptionend>
+#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
+pub struct ExceptionClause {
+    /// When represents each `WHEN` case
+    pub when: Vec<ExceptionWhen>,
+    /// The exception that is being raised or the current exception being 
handled if `None`.
+    ///
+    /// Example
+    /// RAISE;
+    /// RAISE MY_EXCEPTION;
+    /// RAISE USING MESSAGE = "Some error";
+    ///
+    /// BigQuery: 
<https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#raise>
+    /// Snowflake: 
<https://docs.snowflake.com/en/sql-reference/snowflake-scripting/raise>
+    // pub raises: Option<Option<Ident>>,
+    pub raises: Option<Box<Statement>>,

Review Comment:
   ```suggestion
       pub raise: Option<Box<Statement>>,
   ```
   we only have a single value right or?



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to