This is an automated email from the ASF dual-hosted git repository.

github-bot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new eabde4b4 feat: Add RESET to the base dialect #2078 (#2079)
eabde4b4 is described below

commit eabde4b41e9607722c23b96699bbd83e0e9bd343
Author: Christopher Watford <[email protected]>
AuthorDate: Tue Nov 11 03:10:32 2025 -0500

    feat: Add RESET to the base dialect #2078 (#2079)
---
 src/ast/mod.rs            | 56 +++++++++++++++++++++++++++++++++++++++++------
 src/ast/spans.rs          |  1 +
 src/parser/mod.rs         | 13 +++++++++++
 tests/sqlparser_common.rs | 23 +++++++++++++++++++
 4 files changed, 86 insertions(+), 7 deletions(-)

diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index 176d3654..4636e4ba 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -2787,10 +2787,11 @@ impl fmt::Display for Declare {
 }
 
 /// Sql options of a `CREATE TABLE` statement.
-#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Default)]
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
 #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
 pub enum CreateTableOptions {
+    #[default]
     None,
     /// Options specified using the `WITH` keyword.
     /// e.g. `WITH (description = "123")`
@@ -2819,12 +2820,6 @@ pub enum CreateTableOptions {
     TableProperties(Vec<SqlOption>),
 }
 
-impl Default for CreateTableOptions {
-    fn default() -> Self {
-        Self::None
-    }
-}
-
 impl fmt::Display for CreateTableOptions {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self {
@@ -4263,6 +4258,14 @@ pub enum Statement {
     /// ```
     /// 
[Redshift](https://docs.aws.amazon.com/redshift/latest/dg/r_VACUUM_command.html)
     Vacuum(VacuumStatement),
+    /// Restore the value of a run-time parameter to the default value.
+    ///
+    /// ```sql
+    /// RESET configuration_parameter;
+    /// RESET ALL;
+    /// ```
+    /// [PostgreSQL](https://www.postgresql.org/docs/current/sql-reset.html)
+    Reset(ResetStatement),
 }
 
 impl From<Analyze> for Statement {
@@ -5757,6 +5760,7 @@ impl fmt::Display for Statement {
             Statement::AlterSchema(s) => write!(f, "{s}"),
             Statement::Vacuum(s) => write!(f, "{s}"),
             Statement::AlterUser(s) => write!(f, "{s}"),
+            Statement::Reset(s) => write!(f, "{s}"),
         }
     }
 }
@@ -10519,6 +10523,38 @@ impl fmt::Display for VacuumStatement {
     }
 }
 
+/// Variants of the RESET statement
+#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
+pub enum Reset {
+    /// Resets all session parameters to their default values.
+    ALL,
+
+    /// Resets a specific session parameter to its default value.
+    ConfigurationParameter(ObjectName),
+}
+
+/// Resets a session parameter to its default value.
+/// ```sql
+/// RESET { ALL | <configuration_parameter> }
+/// ```
+#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
+pub struct ResetStatement {
+    pub reset: Reset,
+}
+
+impl fmt::Display for ResetStatement {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match &self.reset {
+            Reset::ALL => write!(f, "RESET ALL"),
+            Reset::ConfigurationParameter(param) => write!(f, "RESET {}", 
param),
+        }
+    }
+}
+
 impl From<Set> for Statement {
     fn from(s: Set) -> Self {
         Self::Set(s)
@@ -10759,6 +10795,12 @@ impl From<VacuumStatement> for Statement {
     }
 }
 
+impl From<ResetStatement> for Statement {
+    fn from(r: ResetStatement) -> Self {
+        Self::Reset(r)
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use crate::tokenizer::Location;
diff --git a/src/ast/spans.rs b/src/ast/spans.rs
index 7d2a0009..34edabd9 100644
--- a/src/ast/spans.rs
+++ b/src/ast/spans.rs
@@ -475,6 +475,7 @@ impl Spanned for Statement {
             Statement::AlterSchema(s) => s.span(),
             Statement::Vacuum(..) => Span::empty(),
             Statement::AlterUser(..) => Span::empty(),
+            Statement::Reset(..) => Span::empty(),
         }
     }
 }
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 9a01e510..f43329be 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -656,6 +656,7 @@ impl<'a> Parser<'a> {
                     self.prev_token();
                     self.parse_vacuum()
                 }
+                Keyword::RESET => self.parse_reset(),
                 _ => self.expected("an SQL statement", next_token),
             },
             Token::LParen => {
@@ -17727,6 +17728,18 @@ impl<'a> Parser<'a> {
             _ => self.expected("expected option value", self.peek_token()),
         }
     }
+
+    /// Parses a RESET statement
+    fn parse_reset(&mut self) -> Result<Statement, ParserError> {
+        if self.parse_keyword(Keyword::ALL) {
+            return Ok(Statement::Reset(ResetStatement { reset: Reset::ALL }));
+        }
+
+        let obj = self.parse_object_name(false)?;
+        Ok(Statement::Reset(ResetStatement {
+            reset: Reset::ConfigurationParameter(obj),
+        }))
+    }
 }
 
 fn maybe_prefixed_expr(expr: Expr, prefix: Option<Ident>) -> Expr {
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index f1ba5df0..9ea91c64 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -17632,3 +17632,26 @@ fn parse_generic_unary_ops() {
         );
     }
 }
+
+#[test]
+fn parse_reset_statement() {
+    match verified_stmt("RESET some_parameter") {
+        Statement::Reset(ResetStatement {
+            reset: Reset::ConfigurationParameter(o),
+        }) => assert_eq!(o, ObjectName::from(vec!["some_parameter".into()])),
+        _ => unreachable!(),
+    }
+    match verified_stmt("RESET some_extension.some_parameter") {
+        Statement::Reset(ResetStatement {
+            reset: Reset::ConfigurationParameter(o),
+        }) => assert_eq!(
+            o,
+            ObjectName::from(vec!["some_extension".into(), 
"some_parameter".into()])
+        ),
+        _ => unreachable!(),
+    }
+    match verified_stmt("RESET ALL") {
+        Statement::Reset(ResetStatement { reset }) => assert_eq!(reset, 
Reset::ALL),
+        _ => unreachable!(),
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to