feat: Add RESET to the base dialect #2078 (#2079)

This commit is contained in:
Christopher Watford 2025-11-11 03:10:32 -05:00 committed by GitHub
parent 308a7231bc
commit eabde4b41e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 86 additions and 7 deletions

View file

@ -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;

View file

@ -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(),
}
}
}

View file

@ -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 {

View file

@ -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!(),
}
}