Skip to content

Commit db7b94f

Browse files
authored
support for PAUSE/RESUME MIRROR (#24)
1 parent d03b760 commit db7b94f

File tree

4 files changed

+143
-1
lines changed

4 files changed

+143
-1
lines changed

src/ast/mod.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2146,7 +2146,7 @@ pub enum Statement {
21462146
if_not_exists: bool,
21472147
create_mirror: CreateMirror,
21482148
},
2149-
/// DROP MIRROR [IF EXISTS] mirror_name
2149+
// DROP MIRROR [IF EXISTS] mirror_name
21502150
DropMirror {
21512151
#[cfg_attr(feature = "derive-visitor", drive(skip))]
21522152
if_exists: bool,
@@ -2162,6 +2162,18 @@ pub enum Statement {
21622162
mirror_name: ObjectName,
21632163
with_options: Vec<SqlOption>,
21642164
},
2165+
// DROP MIRROR [IF EXISTS] mirror_name
2166+
PauseMirror {
2167+
#[cfg_attr(feature = "derive-visitor", drive(skip))]
2168+
if_exists: bool,
2169+
mirror_name: ObjectName,
2170+
},
2171+
// RESUME MIRROR [IF EXISTS] mirror_name
2172+
ResumeMirror {
2173+
#[cfg_attr(feature = "derive-visitor", drive(skip))]
2174+
if_exists: bool,
2175+
mirror_name: ObjectName,
2176+
},
21652177
}
21662178

21672179
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
@@ -3656,6 +3668,28 @@ impl fmt::Display for Statement {
36563668
write!(f, "EXECUTE MIRROR {mirror_name}", mirror_name = mirror_name)?;
36573669
Ok(())
36583670
}
3671+
Statement::PauseMirror {
3672+
if_exists,
3673+
mirror_name,
3674+
} => {
3675+
write!(
3676+
f,
3677+
"PAUSE MIRROR {if_exists}{mirror_name}",
3678+
if_exists = if *if_exists { "IF EXISTS " } else { "" },
3679+
)?;
3680+
Ok(())
3681+
}
3682+
Statement::ResumeMirror {
3683+
if_exists,
3684+
mirror_name,
3685+
} => {
3686+
write!(
3687+
f,
3688+
"RESUME MIRROR {if_exists}{mirror_name}",
3689+
if_exists = if *if_exists { "IF EXISTS " } else { "" },
3690+
)?;
3691+
Ok(())
3692+
}
36593693
Statement::ResyncMirror {
36603694
if_exists,
36613695
mirror_name,

src/keywords.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ define_keywords!(
471471
PARTITIONS,
472472
PASSWORD,
473473
PATTERN,
474+
PAUSE,
474475
PEER,
475476
PERCENT,
476477
PERCENTILE_CONT,
@@ -534,6 +535,7 @@ define_keywords!(
534535
RESPECT,
535536
RESTRICT,
536537
RESULT,
538+
RESUME,
537539
RESYNC,
538540
RETAIN,
539541
RETURN,

src/parser/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ impl<'a> Parser<'a> {
522522
// `PRAGMA` is sqlite specific https://www.sqlite.org/pragma.html
523523
Keyword::PRAGMA => Ok(self.parse_pragma()?),
524524
Keyword::RESYNC => Ok(self.parse_resync()?),
525+
Keyword::PAUSE => Ok(self.parse_pause_mirror()?),
526+
Keyword::RESUME => Ok(self.parse_resume_mirror()?),
525527
_ => self.expected("an SQL statement", next_token),
526528
},
527529
Token::LParen => {
@@ -8104,6 +8106,26 @@ impl<'a> Parser<'a> {
81048106
})
81058107
}
81068108

8109+
pub fn parse_pause_mirror(&mut self) -> Result<Statement, ParserError> {
8110+
self.expect_keyword(Keyword::MIRROR)?;
8111+
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
8112+
let mirror_name = self.parse_object_name()?;
8113+
Ok(Statement::PauseMirror {
8114+
if_exists,
8115+
mirror_name,
8116+
})
8117+
}
8118+
8119+
pub fn parse_resume_mirror(&mut self) -> Result<Statement, ParserError> {
8120+
self.expect_keyword(Keyword::MIRROR)?;
8121+
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
8122+
let mirror_name = self.parse_object_name()?;
8123+
Ok(Statement::ResumeMirror {
8124+
if_exists,
8125+
mirror_name,
8126+
})
8127+
}
8128+
81078129
/// The index of the first unprocessed token.
81088130
pub fn index(&self) -> usize {
81098131
self.index

tests/sqlparser_postgres.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3610,6 +3610,20 @@ fn parse_create_mirror_with_schema() {
36103610

36113611
#[test]
36123612
fn parse_drop_mirror() {
3613+
match pg().verified_stmt("DROP MIRROR m1") {
3614+
Statement::DropMirror {
3615+
if_exists,
3616+
mirror_name,
3617+
} => {
3618+
assert!(!if_exists);
3619+
assert_eq!(mirror_name, ObjectName(vec![Ident::new("m1")]));
3620+
}
3621+
_ => unreachable!(),
3622+
}
3623+
}
3624+
3625+
#[test]
3626+
fn parse_drop_mirror_if_exists() {
36133627
match pg().verified_stmt("DROP MIRROR IF EXISTS m1") {
36143628
Statement::DropMirror {
36153629
if_exists,
@@ -3622,8 +3636,78 @@ fn parse_drop_mirror() {
36223636
}
36233637
}
36243638

3639+
#[test]
3640+
fn parse_pause_mirror() {
3641+
match pg().verified_stmt("PAUSE MIRROR m1") {
3642+
Statement::PauseMirror {
3643+
if_exists,
3644+
mirror_name,
3645+
} => {
3646+
assert!(!if_exists);
3647+
assert_eq!(mirror_name, ObjectName(vec![Ident::new("m1")]));
3648+
}
3649+
_ => unreachable!(),
3650+
}
3651+
}
3652+
3653+
#[test]
3654+
fn parse_pause_mirror_if_exists() {
3655+
match pg().verified_stmt("PAUSE MIRROR IF EXISTS m1") {
3656+
Statement::PauseMirror {
3657+
if_exists,
3658+
mirror_name,
3659+
} => {
3660+
assert!(if_exists);
3661+
assert_eq!(mirror_name, ObjectName(vec![Ident::new("m1")]));
3662+
}
3663+
_ => unreachable!(),
3664+
}
3665+
}
3666+
3667+
#[test]
3668+
fn parse_resume_mirror() {
3669+
match pg().verified_stmt("RESUME MIRROR m1") {
3670+
Statement::ResumeMirror {
3671+
if_exists,
3672+
mirror_name,
3673+
} => {
3674+
assert!(!if_exists);
3675+
assert_eq!(mirror_name, ObjectName(vec![Ident::new("m1")]));
3676+
}
3677+
_ => unreachable!(),
3678+
}
3679+
}
3680+
3681+
#[test]
3682+
fn parse_resume_mirror_if_exists() {
3683+
match pg().verified_stmt("RESUME MIRROR IF EXISTS m1") {
3684+
Statement::ResumeMirror {
3685+
if_exists,
3686+
mirror_name,
3687+
} => {
3688+
assert!(if_exists);
3689+
assert_eq!(mirror_name, ObjectName(vec![Ident::new("m1")]));
3690+
}
3691+
_ => unreachable!(),
3692+
}
3693+
}
3694+
36253695
#[test]
36263696
fn parse_drop_peer() {
3697+
match pg().verified_stmt("DROP PEER p1") {
3698+
Statement::DropPeer {
3699+
if_exists,
3700+
peer_name,
3701+
} => {
3702+
assert!(!if_exists);
3703+
assert_eq!(peer_name, ObjectName(vec![Ident::new("p1")]));
3704+
}
3705+
_ => unreachable!(),
3706+
}
3707+
}
3708+
3709+
#[test]
3710+
fn parse_drop_peer_if_exists() {
36273711
match pg().verified_stmt("DROP PEER IF EXISTS p1") {
36283712
Statement::DropPeer {
36293713
if_exists,

0 commit comments

Comments
 (0)