Skip to content

Commit 93450cc

Browse files
authored
Add Snowflake COPY/REVOKE CURRENT GRANTS option (#1926)
1 parent 1a33abd commit 93450cc

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

src/ast/mod.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3996,6 +3996,7 @@ pub enum Statement {
39963996
with_grant_option: bool,
39973997
as_grantor: Option<Ident>,
39983998
granted_by: Option<Ident>,
3999+
current_grants: Option<CurrentGrantsKind>,
39994000
},
40004001
/// ```sql
40014002
/// DENY privileges ON object TO grantees
@@ -4312,6 +4313,28 @@ pub enum Statement {
43124313
Return(ReturnStatement),
43134314
}
43144315

4316+
/// ```sql
4317+
/// {COPY | REVOKE} CURRENT GRANTS
4318+
/// ```
4319+
///
4320+
/// - [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/grant-ownership#optional-parameters)
4321+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4322+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4323+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4324+
pub enum CurrentGrantsKind {
4325+
CopyCurrentGrants,
4326+
RevokeCurrentGrants,
4327+
}
4328+
4329+
impl fmt::Display for CurrentGrantsKind {
4330+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4331+
match self {
4332+
CurrentGrantsKind::CopyCurrentGrants => write!(f, "COPY CURRENT GRANTS"),
4333+
CurrentGrantsKind::RevokeCurrentGrants => write!(f, "REVOKE CURRENT GRANTS"),
4334+
}
4335+
}
4336+
}
4337+
43154338
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
43164339
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
43174340
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
@@ -5715,6 +5738,7 @@ impl fmt::Display for Statement {
57155738
with_grant_option,
57165739
as_grantor,
57175740
granted_by,
5741+
current_grants,
57185742
} => {
57195743
write!(f, "GRANT {privileges} ")?;
57205744
if let Some(objects) = objects {
@@ -5724,6 +5748,9 @@ impl fmt::Display for Statement {
57245748
if *with_grant_option {
57255749
write!(f, " WITH GRANT OPTION")?;
57265750
}
5751+
if let Some(current_grants) = current_grants {
5752+
write!(f, " {current_grants}")?;
5753+
}
57275754
if let Some(grantor) = as_grantor {
57285755
write!(f, " AS {grantor}")?;
57295756
}

src/parser/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13794,6 +13794,15 @@ impl<'a> Parser<'a> {
1379413794
let with_grant_option =
1379513795
self.parse_keywords(&[Keyword::WITH, Keyword::GRANT, Keyword::OPTION]);
1379613796

13797+
let current_grants =
13798+
if self.parse_keywords(&[Keyword::COPY, Keyword::CURRENT, Keyword::GRANTS]) {
13799+
Some(CurrentGrantsKind::CopyCurrentGrants)
13800+
} else if self.parse_keywords(&[Keyword::REVOKE, Keyword::CURRENT, Keyword::GRANTS]) {
13801+
Some(CurrentGrantsKind::RevokeCurrentGrants)
13802+
} else {
13803+
None
13804+
};
13805+
1379713806
let as_grantor = if self.parse_keywords(&[Keyword::AS]) {
1379813807
Some(self.parse_identifier()?)
1379913808
} else {
@@ -13813,6 +13822,7 @@ impl<'a> Parser<'a> {
1381313822
with_grant_option,
1381413823
as_grantor,
1381513824
granted_by,
13825+
current_grants,
1381613826
})
1381713827
}
1381813828

tests/sqlparser_common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9440,6 +9440,8 @@ fn parse_grant() {
94409440
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO a:b");
94419441
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO GROUP group1");
94429442
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST");
9443+
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST COPY CURRENT GRANTS");
9444+
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST REVOKE CURRENT GRANTS");
94439445
verified_stmt("GRANT USAGE ON DATABASE db1 TO ROLE role1");
94449446
verified_stmt("GRANT USAGE ON WAREHOUSE wh1 TO ROLE role1");
94459447
verified_stmt("GRANT OWNERSHIP ON INTEGRATION int1 TO ROLE role1");

tests/sqlparser_mysql.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3616,6 +3616,7 @@ fn parse_grant() {
36163616
with_grant_option,
36173617
as_grantor: _,
36183618
granted_by,
3619+
current_grants: _,
36193620
} = stmt
36203621
{
36213622
assert_eq!(

0 commit comments

Comments
 (0)