Skip to content

Commit 7f1304a

Browse files
yoavcloudayman-sigma
authored andcommitted
Add Snowflake COPY/REVOKE CURRENT GRANTS option (apache#1926)
1 parent 54682a7 commit 7f1304a

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
@@ -4025,6 +4025,7 @@ pub enum Statement {
40254025
with_grant_option: bool,
40264026
as_grantor: Option<Ident>,
40274027
granted_by: Option<Ident>,
4028+
current_grants: Option<CurrentGrantsKind>,
40284029
},
40294030
/// ```sql
40304031
/// DENY privileges ON object TO grantees
@@ -4341,6 +4342,28 @@ pub enum Statement {
43414342
Return(ReturnStatement),
43424343
}
43434344

4345+
/// ```sql
4346+
/// {COPY | REVOKE} CURRENT GRANTS
4347+
/// ```
4348+
///
4349+
/// - [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/grant-ownership#optional-parameters)
4350+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4351+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4352+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4353+
pub enum CurrentGrantsKind {
4354+
CopyCurrentGrants,
4355+
RevokeCurrentGrants,
4356+
}
4357+
4358+
impl fmt::Display for CurrentGrantsKind {
4359+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4360+
match self {
4361+
CurrentGrantsKind::CopyCurrentGrants => write!(f, "COPY CURRENT GRANTS"),
4362+
CurrentGrantsKind::RevokeCurrentGrants => write!(f, "REVOKE CURRENT GRANTS"),
4363+
}
4364+
}
4365+
}
4366+
43444367
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
43454368
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
43464369
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
@@ -5744,6 +5767,7 @@ impl fmt::Display for Statement {
57445767
with_grant_option,
57455768
as_grantor,
57465769
granted_by,
5770+
current_grants,
57475771
} => {
57485772
write!(f, "GRANT {privileges} ")?;
57495773
if let Some(objects) = objects {
@@ -5753,6 +5777,9 @@ impl fmt::Display for Statement {
57535777
if *with_grant_option {
57545778
write!(f, " WITH GRANT OPTION")?;
57555779
}
5780+
if let Some(current_grants) = current_grants {
5781+
write!(f, " {current_grants}")?;
5782+
}
57565783
if let Some(grantor) = as_grantor {
57575784
write!(f, " AS {grantor}")?;
57585785
}

src/parser/mod.rs

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

13829+
let current_grants =
13830+
if self.parse_keywords(&[Keyword::COPY, Keyword::CURRENT, Keyword::GRANTS]) {
13831+
Some(CurrentGrantsKind::CopyCurrentGrants)
13832+
} else if self.parse_keywords(&[Keyword::REVOKE, Keyword::CURRENT, Keyword::GRANTS]) {
13833+
Some(CurrentGrantsKind::RevokeCurrentGrants)
13834+
} else {
13835+
None
13836+
};
13837+
1382913838
let as_grantor = if self.parse_keywords(&[Keyword::AS]) {
1383013839
Some(self.parse_identifier()?)
1383113840
} else {
@@ -13845,6 +13854,7 @@ impl<'a> Parser<'a> {
1384513854
with_grant_option,
1384613855
as_grantor,
1384713856
granted_by,
13857+
current_grants,
1384813858
})
1384913859
}
1385013860

tests/sqlparser_common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9441,6 +9441,8 @@ fn parse_grant() {
94419441
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO a:b");
94429442
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO GROUP group1");
94439443
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST");
9444+
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST COPY CURRENT GRANTS");
9445+
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST REVOKE CURRENT GRANTS");
94449446
verified_stmt("GRANT USAGE ON DATABASE db1 TO ROLE role1");
94459447
verified_stmt("GRANT USAGE ON WAREHOUSE wh1 TO ROLE role1");
94469448
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)