Skip to content

Commit eabde4b

Browse files
authored
feat: Add RESET to the base dialect #2078 (#2079)
1 parent 308a723 commit eabde4b

File tree

4 files changed

+86
-7
lines changed

4 files changed

+86
-7
lines changed

src/ast/mod.rs

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,10 +2787,11 @@ impl fmt::Display for Declare {
27872787
}
27882788

27892789
/// Sql options of a `CREATE TABLE` statement.
2790-
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2790+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Default)]
27912791
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
27922792
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
27932793
pub enum CreateTableOptions {
2794+
#[default]
27942795
None,
27952796
/// Options specified using the `WITH` keyword.
27962797
/// e.g. `WITH (description = "123")`
@@ -2819,12 +2820,6 @@ pub enum CreateTableOptions {
28192820
TableProperties(Vec<SqlOption>),
28202821
}
28212822

2822-
impl Default for CreateTableOptions {
2823-
fn default() -> Self {
2824-
Self::None
2825-
}
2826-
}
2827-
28282823
impl fmt::Display for CreateTableOptions {
28292824
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
28302825
match self {
@@ -4263,6 +4258,14 @@ pub enum Statement {
42634258
/// ```
42644259
/// [Redshift](https://docs.aws.amazon.com/redshift/latest/dg/r_VACUUM_command.html)
42654260
Vacuum(VacuumStatement),
4261+
/// Restore the value of a run-time parameter to the default value.
4262+
///
4263+
/// ```sql
4264+
/// RESET configuration_parameter;
4265+
/// RESET ALL;
4266+
/// ```
4267+
/// [PostgreSQL](https://www.postgresql.org/docs/current/sql-reset.html)
4268+
Reset(ResetStatement),
42664269
}
42674270

42684271
impl From<Analyze> for Statement {
@@ -5757,6 +5760,7 @@ impl fmt::Display for Statement {
57575760
Statement::AlterSchema(s) => write!(f, "{s}"),
57585761
Statement::Vacuum(s) => write!(f, "{s}"),
57595762
Statement::AlterUser(s) => write!(f, "{s}"),
5763+
Statement::Reset(s) => write!(f, "{s}"),
57605764
}
57615765
}
57625766
}
@@ -10519,6 +10523,38 @@ impl fmt::Display for VacuumStatement {
1051910523
}
1052010524
}
1052110525

10526+
/// Variants of the RESET statement
10527+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10528+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10529+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10530+
pub enum Reset {
10531+
/// Resets all session parameters to their default values.
10532+
ALL,
10533+
10534+
/// Resets a specific session parameter to its default value.
10535+
ConfigurationParameter(ObjectName),
10536+
}
10537+
10538+
/// Resets a session parameter to its default value.
10539+
/// ```sql
10540+
/// RESET { ALL | <configuration_parameter> }
10541+
/// ```
10542+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10543+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10544+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10545+
pub struct ResetStatement {
10546+
pub reset: Reset,
10547+
}
10548+
10549+
impl fmt::Display for ResetStatement {
10550+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10551+
match &self.reset {
10552+
Reset::ALL => write!(f, "RESET ALL"),
10553+
Reset::ConfigurationParameter(param) => write!(f, "RESET {}", param),
10554+
}
10555+
}
10556+
}
10557+
1052210558
impl From<Set> for Statement {
1052310559
fn from(s: Set) -> Self {
1052410560
Self::Set(s)
@@ -10759,6 +10795,12 @@ impl From<VacuumStatement> for Statement {
1075910795
}
1076010796
}
1076110797

10798+
impl From<ResetStatement> for Statement {
10799+
fn from(r: ResetStatement) -> Self {
10800+
Self::Reset(r)
10801+
}
10802+
}
10803+
1076210804
#[cfg(test)]
1076310805
mod tests {
1076410806
use crate::tokenizer::Location;

src/ast/spans.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ impl Spanned for Statement {
475475
Statement::AlterSchema(s) => s.span(),
476476
Statement::Vacuum(..) => Span::empty(),
477477
Statement::AlterUser(..) => Span::empty(),
478+
Statement::Reset(..) => Span::empty(),
478479
}
479480
}
480481
}

src/parser/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ impl<'a> Parser<'a> {
656656
self.prev_token();
657657
self.parse_vacuum()
658658
}
659+
Keyword::RESET => self.parse_reset(),
659660
_ => self.expected("an SQL statement", next_token),
660661
},
661662
Token::LParen => {
@@ -17727,6 +17728,18 @@ impl<'a> Parser<'a> {
1772717728
_ => self.expected("expected option value", self.peek_token()),
1772817729
}
1772917730
}
17731+
17732+
/// Parses a RESET statement
17733+
fn parse_reset(&mut self) -> Result<Statement, ParserError> {
17734+
if self.parse_keyword(Keyword::ALL) {
17735+
return Ok(Statement::Reset(ResetStatement { reset: Reset::ALL }));
17736+
}
17737+
17738+
let obj = self.parse_object_name(false)?;
17739+
Ok(Statement::Reset(ResetStatement {
17740+
reset: Reset::ConfigurationParameter(obj),
17741+
}))
17742+
}
1773017743
}
1773117744

1773217745
fn maybe_prefixed_expr(expr: Expr, prefix: Option<Ident>) -> Expr {

tests/sqlparser_common.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17632,3 +17632,26 @@ fn parse_generic_unary_ops() {
1763217632
);
1763317633
}
1763417634
}
17635+
17636+
#[test]
17637+
fn parse_reset_statement() {
17638+
match verified_stmt("RESET some_parameter") {
17639+
Statement::Reset(ResetStatement {
17640+
reset: Reset::ConfigurationParameter(o),
17641+
}) => assert_eq!(o, ObjectName::from(vec!["some_parameter".into()])),
17642+
_ => unreachable!(),
17643+
}
17644+
match verified_stmt("RESET some_extension.some_parameter") {
17645+
Statement::Reset(ResetStatement {
17646+
reset: Reset::ConfigurationParameter(o),
17647+
}) => assert_eq!(
17648+
o,
17649+
ObjectName::from(vec!["some_extension".into(), "some_parameter".into()])
17650+
),
17651+
_ => unreachable!(),
17652+
}
17653+
match verified_stmt("RESET ALL") {
17654+
Statement::Reset(ResetStatement { reset }) => assert_eq!(reset, Reset::ALL),
17655+
_ => unreachable!(),
17656+
}
17657+
}

0 commit comments

Comments
 (0)