From ec698e85de9b897e8d1159c1e895f6227e25e727 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sat, 26 Feb 2022 16:53:38 +0000 Subject: [PATCH] Add keyword to queries for PARALLEL execution --- lib/src/dbs/iterator.rs | 6 ++++++ lib/src/sql/statements/create.rs | 6 ++++++ lib/src/sql/statements/delete.rs | 6 ++++++ lib/src/sql/statements/insert.rs | 6 ++++++ lib/src/sql/statements/relate.rs | 6 ++++++ lib/src/sql/statements/select.rs | 6 ++++++ lib/src/sql/statements/update.rs | 6 ++++++ 7 files changed, 42 insertions(+) diff --git a/lib/src/dbs/iterator.rs b/lib/src/dbs/iterator.rs index e7c54870..f48d548c 100644 --- a/lib/src/dbs/iterator.rs +++ b/lib/src/dbs/iterator.rs @@ -57,6 +57,7 @@ impl<'a> From<&'a SelectStatement> for Iterator<'a> { order: v.order.as_ref(), limit: v.limit.as_ref(), start: v.start.as_ref(), + parallel: v.parallel, ..Iterator::default() } } @@ -66,6 +67,7 @@ impl<'a> From<&'a CreateStatement> for Iterator<'a> { fn from(v: &'a CreateStatement) -> Self { Iterator { stmt: Statement::from(v), + parallel: v.parallel, ..Iterator::default() } } @@ -75,6 +77,7 @@ impl<'a> From<&'a UpdateStatement> for Iterator<'a> { fn from(v: &'a UpdateStatement) -> Self { Iterator { stmt: Statement::from(v), + parallel: v.parallel, ..Iterator::default() } } @@ -84,6 +87,7 @@ impl<'a> From<&'a RelateStatement> for Iterator<'a> { fn from(v: &'a RelateStatement) -> Self { Iterator { stmt: Statement::from(v), + parallel: v.parallel, ..Iterator::default() } } @@ -93,6 +97,7 @@ impl<'a> From<&'a DeleteStatement> for Iterator<'a> { fn from(v: &'a DeleteStatement) -> Self { Iterator { stmt: Statement::from(v), + parallel: v.parallel, ..Iterator::default() } } @@ -102,6 +107,7 @@ impl<'a> From<&'a InsertStatement> for Iterator<'a> { fn from(v: &'a InsertStatement) -> Self { Iterator { stmt: Statement::from(v), + parallel: v.parallel, ..Iterator::default() } } diff --git a/lib/src/sql/statements/create.rs b/lib/src/sql/statements/create.rs index d014951f..d36861aa 100644 --- a/lib/src/sql/statements/create.rs +++ b/lib/src/sql/statements/create.rs @@ -23,6 +23,7 @@ pub struct CreateStatement { pub data: Option, pub output: Option, pub timeout: Option, + pub parallel: bool, } impl CreateStatement { @@ -71,6 +72,9 @@ impl fmt::Display for CreateStatement { if let Some(ref v) = self.timeout { write!(f, " {}", v)? } + if self.parallel { + write!(f, " PARALLEL")? + } Ok(()) } } @@ -82,6 +86,7 @@ pub fn create(i: &str) -> IResult<&str, CreateStatement> { let (i, data) = opt(preceded(shouldbespace, data))(i)?; let (i, output) = opt(preceded(shouldbespace, output))(i)?; let (i, timeout) = opt(preceded(shouldbespace, timeout))(i)?; + let (i, parallel) = opt(preceded(shouldbespace, tag_no_case("PARALLEL")))(i)?; Ok(( i, CreateStatement { @@ -89,6 +94,7 @@ pub fn create(i: &str) -> IResult<&str, CreateStatement> { data, output, timeout, + parallel: parallel.is_some(), }, )) } diff --git a/lib/src/sql/statements/delete.rs b/lib/src/sql/statements/delete.rs index 09cf05cd..72d42b2f 100644 --- a/lib/src/sql/statements/delete.rs +++ b/lib/src/sql/statements/delete.rs @@ -24,6 +24,7 @@ pub struct DeleteStatement { pub cond: Option, pub output: Option, pub timeout: Option, + pub parallel: bool, } impl DeleteStatement { @@ -72,6 +73,9 @@ impl fmt::Display for DeleteStatement { if let Some(ref v) = self.timeout { write!(f, " {}", v)? } + if self.parallel { + write!(f, " PARALLEL")? + } Ok(()) } } @@ -84,6 +88,7 @@ pub fn delete(i: &str) -> IResult<&str, DeleteStatement> { let (i, cond) = opt(preceded(shouldbespace, cond))(i)?; let (i, output) = opt(preceded(shouldbespace, output))(i)?; let (i, timeout) = opt(preceded(shouldbespace, timeout))(i)?; + let (i, parallel) = opt(preceded(shouldbespace, tag_no_case("PARALLEL")))(i)?; Ok(( i, DeleteStatement { @@ -91,6 +96,7 @@ pub fn delete(i: &str) -> IResult<&str, DeleteStatement> { cond, output, timeout, + parallel: parallel.is_some(), }, )) } diff --git a/lib/src/sql/statements/insert.rs b/lib/src/sql/statements/insert.rs index 5d9560ef..3f3fbce1 100644 --- a/lib/src/sql/statements/insert.rs +++ b/lib/src/sql/statements/insert.rs @@ -27,6 +27,7 @@ pub struct InsertStatement { pub update: Option, pub output: Option, pub timeout: Option, + pub parallel: bool, } impl InsertStatement { @@ -80,6 +81,9 @@ impl fmt::Display for InsertStatement { if let Some(ref v) = self.timeout { write!(f, " {}", v)? } + if self.parallel { + write!(f, " PARALLEL")? + } Ok(()) } } @@ -93,6 +97,7 @@ pub fn insert(i: &str) -> IResult<&str, InsertStatement> { let (i, update) = opt(preceded(shouldbespace, update))(i)?; let (i, output) = opt(preceded(shouldbespace, output))(i)?; let (i, timeout) = opt(preceded(shouldbespace, timeout))(i)?; + let (i, parallel) = opt(preceded(shouldbespace, tag_no_case("PARALLEL")))(i)?; Ok(( i, InsertStatement { @@ -102,6 +107,7 @@ pub fn insert(i: &str) -> IResult<&str, InsertStatement> { update, output, timeout, + parallel: parallel.is_some(), }, )) } diff --git a/lib/src/sql/statements/relate.rs b/lib/src/sql/statements/relate.rs index 239ae555..94aebdef 100644 --- a/lib/src/sql/statements/relate.rs +++ b/lib/src/sql/statements/relate.rs @@ -30,6 +30,7 @@ pub struct RelateStatement { pub data: Option, pub output: Option, pub timeout: Option, + pub parallel: bool, } impl RelateStatement { @@ -81,6 +82,9 @@ impl fmt::Display for RelateStatement { if let Some(ref v) = self.timeout { write!(f, " {}", v)? } + if self.parallel { + write!(f, " PARALLEL")? + } Ok(()) } } @@ -93,6 +97,7 @@ pub fn relate(i: &str) -> IResult<&str, RelateStatement> { let (i, data) = opt(preceded(shouldbespace, data))(i)?; let (i, output) = opt(preceded(shouldbespace, output))(i)?; let (i, timeout) = opt(preceded(shouldbespace, timeout))(i)?; + let (i, parallel) = opt(preceded(shouldbespace, tag_no_case("PARALLEL")))(i)?; Ok(( i, RelateStatement { @@ -103,6 +108,7 @@ pub fn relate(i: &str) -> IResult<&str, RelateStatement> { data, output, timeout, + parallel: parallel.is_some(), }, )) } diff --git a/lib/src/sql/statements/select.rs b/lib/src/sql/statements/select.rs index f7580363..58f557ed 100644 --- a/lib/src/sql/statements/select.rs +++ b/lib/src/sql/statements/select.rs @@ -37,6 +37,7 @@ pub struct SelectStatement { pub fetch: Option, pub version: Option, pub timeout: Option, + pub parallel: bool, } impl SelectStatement { @@ -114,6 +115,9 @@ impl fmt::Display for SelectStatement { if let Some(ref v) = self.timeout { write!(f, " {}", v)? } + if self.parallel { + write!(f, " PARALLEL")? + } Ok(()) } } @@ -135,6 +139,7 @@ pub fn select(i: &str) -> IResult<&str, SelectStatement> { let (i, fetch) = opt(preceded(shouldbespace, fetch))(i)?; let (i, version) = opt(preceded(shouldbespace, version))(i)?; let (i, timeout) = opt(preceded(shouldbespace, timeout))(i)?; + let (i, parallel) = opt(preceded(shouldbespace, tag_no_case("PARALLEL")))(i)?; Ok(( i, SelectStatement { @@ -149,6 +154,7 @@ pub fn select(i: &str) -> IResult<&str, SelectStatement> { fetch, version, timeout, + parallel: parallel.is_some(), }, )) } diff --git a/lib/src/sql/statements/update.rs b/lib/src/sql/statements/update.rs index 4840cde9..2eb3d2e0 100644 --- a/lib/src/sql/statements/update.rs +++ b/lib/src/sql/statements/update.rs @@ -25,6 +25,7 @@ pub struct UpdateStatement { pub cond: Option, pub output: Option, pub timeout: Option, + pub parallel: bool, } impl UpdateStatement { @@ -76,6 +77,9 @@ impl fmt::Display for UpdateStatement { if let Some(ref v) = self.timeout { write!(f, " {}", v)? } + if self.parallel { + write!(f, " PARALLEL")? + } Ok(()) } } @@ -88,6 +92,7 @@ pub fn update(i: &str) -> IResult<&str, UpdateStatement> { let (i, cond) = opt(preceded(shouldbespace, cond))(i)?; let (i, output) = opt(preceded(shouldbespace, output))(i)?; let (i, timeout) = opt(preceded(shouldbespace, timeout))(i)?; + let (i, parallel) = opt(preceded(shouldbespace, tag_no_case("PARALLEL")))(i)?; Ok(( i, UpdateStatement { @@ -96,6 +101,7 @@ pub fn update(i: &str) -> IResult<&str, UpdateStatement> { cond, output, timeout, + parallel: parallel.is_some(), }, )) }