Skip to content

support for PAUSE MIRROR #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2146,7 +2146,7 @@ pub enum Statement {
if_not_exists: bool,
create_mirror: CreateMirror,
},
/// DROP MIRROR [IF EXISTS] mirror_name
// DROP MIRROR [IF EXISTS] mirror_name
DropMirror {
#[cfg_attr(feature = "derive-visitor", drive(skip))]
if_exists: bool,
Expand All @@ -2162,6 +2162,18 @@ pub enum Statement {
mirror_name: ObjectName,
with_options: Vec<SqlOption>,
},
// DROP MIRROR [IF EXISTS] mirror_name
PauseMirror {
#[cfg_attr(feature = "derive-visitor", drive(skip))]
if_exists: bool,
mirror_name: ObjectName,
},
// RESUME MIRROR [IF EXISTS] mirror_name
ResumeMirror {
#[cfg_attr(feature = "derive-visitor", drive(skip))]
if_exists: bool,
mirror_name: ObjectName,
},
}

#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
Expand Down Expand Up @@ -3656,6 +3668,28 @@ impl fmt::Display for Statement {
write!(f, "EXECUTE MIRROR {mirror_name}", mirror_name = mirror_name)?;
Ok(())
}
Statement::PauseMirror {
if_exists,
mirror_name,
} => {
write!(
f,
"PAUSE MIRROR {if_exists}{mirror_name}",
if_exists = if *if_exists { "IF EXISTS " } else { "" },
)?;
Ok(())
}
Statement::ResumeMirror {
if_exists,
mirror_name,
} => {
write!(
f,
"RESUME MIRROR {if_exists}{mirror_name}",
if_exists = if *if_exists { "IF EXISTS " } else { "" },
)?;
Ok(())
}
Statement::ResyncMirror {
if_exists,
mirror_name,
Expand Down
2 changes: 2 additions & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ define_keywords!(
PARTITIONS,
PASSWORD,
PATTERN,
PAUSE,
PEER,
PERCENT,
PERCENTILE_CONT,
Expand Down Expand Up @@ -534,6 +535,7 @@ define_keywords!(
RESPECT,
RESTRICT,
RESULT,
RESUME,
RESYNC,
RETAIN,
RETURN,
Expand Down
22 changes: 22 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ impl<'a> Parser<'a> {
// `PRAGMA` is sqlite specific https://www.sqlite.org/pragma.html
Keyword::PRAGMA => Ok(self.parse_pragma()?),
Keyword::RESYNC => Ok(self.parse_resync()?),
Keyword::PAUSE => Ok(self.parse_pause_mirror()?),
Keyword::RESUME => Ok(self.parse_resume_mirror()?),
_ => self.expected("an SQL statement", next_token),
},
Token::LParen => {
Expand Down Expand Up @@ -8104,6 +8106,26 @@ impl<'a> Parser<'a> {
})
}

pub fn parse_pause_mirror(&mut self) -> Result<Statement, ParserError> {
self.expect_keyword(Keyword::MIRROR)?;
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
let mirror_name = self.parse_object_name()?;
Ok(Statement::PauseMirror {
if_exists,
mirror_name,
})
}

pub fn parse_resume_mirror(&mut self) -> Result<Statement, ParserError> {
self.expect_keyword(Keyword::MIRROR)?;
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
let mirror_name = self.parse_object_name()?;
Ok(Statement::ResumeMirror {
if_exists,
mirror_name,
})
}

/// The index of the first unprocessed token.
pub fn index(&self) -> usize {
self.index
Expand Down
84 changes: 84 additions & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3610,6 +3610,20 @@ fn parse_create_mirror_with_schema() {

#[test]
fn parse_drop_mirror() {
match pg().verified_stmt("DROP MIRROR m1") {
Statement::DropMirror {
if_exists,
mirror_name,
} => {
assert!(!if_exists);
assert_eq!(mirror_name, ObjectName(vec![Ident::new("m1")]));
}
_ => unreachable!(),
}
}

#[test]
fn parse_drop_mirror_if_exists() {
match pg().verified_stmt("DROP MIRROR IF EXISTS m1") {
Statement::DropMirror {
if_exists,
Expand All @@ -3622,8 +3636,78 @@ fn parse_drop_mirror() {
}
}

#[test]
fn parse_pause_mirror() {
match pg().verified_stmt("PAUSE MIRROR m1") {
Statement::PauseMirror {
if_exists,
mirror_name,
} => {
assert!(!if_exists);
assert_eq!(mirror_name, ObjectName(vec![Ident::new("m1")]));
}
_ => unreachable!(),
}
}

#[test]
fn parse_pause_mirror_if_exists() {
match pg().verified_stmt("PAUSE MIRROR IF EXISTS m1") {
Statement::PauseMirror {
if_exists,
mirror_name,
} => {
assert!(if_exists);
assert_eq!(mirror_name, ObjectName(vec![Ident::new("m1")]));
}
_ => unreachable!(),
}
}

#[test]
fn parse_resume_mirror() {
match pg().verified_stmt("RESUME MIRROR m1") {
Statement::ResumeMirror {
if_exists,
mirror_name,
} => {
assert!(!if_exists);
assert_eq!(mirror_name, ObjectName(vec![Ident::new("m1")]));
}
_ => unreachable!(),
}
}

#[test]
fn parse_resume_mirror_if_exists() {
match pg().verified_stmt("RESUME MIRROR IF EXISTS m1") {
Statement::ResumeMirror {
if_exists,
mirror_name,
} => {
assert!(if_exists);
assert_eq!(mirror_name, ObjectName(vec![Ident::new("m1")]));
}
_ => unreachable!(),
}
}

#[test]
fn parse_drop_peer() {
match pg().verified_stmt("DROP PEER p1") {
Statement::DropPeer {
if_exists,
peer_name,
} => {
assert!(!if_exists);
assert_eq!(peer_name, ObjectName(vec![Ident::new("p1")]));
}
_ => unreachable!(),
}
}

#[test]
fn parse_drop_peer_if_exists() {
match pg().verified_stmt("DROP PEER IF EXISTS p1") {
Statement::DropPeer {
if_exists,
Expand Down