Skip to content

Commit 6a5ef48

Browse files
authored
Snowflake: Support GRANT CREATE SCHEMA GRANT .. ON ALL FUNCTIONS IN SCHEMA (#1964)
1 parent 40b187f commit 6a5ef48

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/ast/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6771,6 +6771,7 @@ pub enum ActionCreateObjectType {
67716771
OrganiationListing,
67726772
ReplicationGroup,
67736773
Role,
6774+
Schema,
67746775
Share,
67756776
User,
67766777
Warehouse,
@@ -6792,6 +6793,7 @@ impl fmt::Display for ActionCreateObjectType {
67926793
ActionCreateObjectType::OrganiationListing => write!(f, "ORGANIZATION LISTING"),
67936794
ActionCreateObjectType::ReplicationGroup => write!(f, "REPLICATION GROUP"),
67946795
ActionCreateObjectType::Role => write!(f, "ROLE"),
6796+
ActionCreateObjectType::Schema => write!(f, "SCHEMA"),
67956797
ActionCreateObjectType::Share => write!(f, "SHARE"),
67966798
ActionCreateObjectType::User => write!(f, "USER"),
67976799
ActionCreateObjectType::Warehouse => write!(f, "WAREHOUSE"),
@@ -7029,6 +7031,8 @@ pub enum GrantObjects {
70297031
AllMaterializedViewsInSchema { schemas: Vec<ObjectName> },
70307032
/// Grant privileges on `ALL EXTERNAL TABLES IN SCHEMA <schema_name> [, ...]`
70317033
AllExternalTablesInSchema { schemas: Vec<ObjectName> },
7034+
/// Grant privileges on `ALL FUNCTIONS IN SCHEMA <schema_name> [, ...]`
7035+
AllFunctionsInSchema { schemas: Vec<ObjectName> },
70327036
/// Grant privileges on `FUTURE SCHEMAS IN DATABASE <database_name> [, ...]`
70337037
FutureSchemasInDatabase { databases: Vec<ObjectName> },
70347038
/// Grant privileges on `FUTURE TABLES IN SCHEMA <schema_name> [, ...]`
@@ -7149,6 +7153,13 @@ impl fmt::Display for GrantObjects {
71497153
display_comma_separated(schemas)
71507154
)
71517155
}
7156+
GrantObjects::AllFunctionsInSchema { schemas } => {
7157+
write!(
7158+
f,
7159+
"ALL FUNCTIONS IN SCHEMA {}",
7160+
display_comma_separated(schemas)
7161+
)
7162+
}
71527163
GrantObjects::FutureSchemasInDatabase { databases } => {
71537164
write!(
71547165
f,

src/parser/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14108,6 +14108,15 @@ impl<'a> Parser<'a> {
1410814108
Some(GrantObjects::AllMaterializedViewsInSchema {
1410914109
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
1411014110
})
14111+
} else if self.parse_keywords(&[
14112+
Keyword::ALL,
14113+
Keyword::FUNCTIONS,
14114+
Keyword::IN,
14115+
Keyword::SCHEMA,
14116+
]) {
14117+
Some(GrantObjects::AllFunctionsInSchema {
14118+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
14119+
})
1411114120
} else if self.parse_keywords(&[
1411214121
Keyword::FUTURE,
1411314122
Keyword::SCHEMAS,
@@ -14414,6 +14423,8 @@ impl<'a> Parser<'a> {
1441414423
Some(ActionCreateObjectType::Integration)
1441514424
} else if self.parse_keyword(Keyword::ROLE) {
1441614425
Some(ActionCreateObjectType::Role)
14426+
} else if self.parse_keyword(Keyword::SCHEMA) {
14427+
Some(ActionCreateObjectType::Schema)
1441714428
} else if self.parse_keyword(Keyword::SHARE) {
1441814429
Some(ActionCreateObjectType::Share)
1441914430
} else if self.parse_keyword(Keyword::USER) {

tests/sqlparser_common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9528,6 +9528,7 @@ fn parse_grant() {
95289528
verified_stmt("GRANT SELECT ON ALL VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
95299529
verified_stmt("GRANT SELECT ON ALL MATERIALIZED VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
95309530
verified_stmt("GRANT SELECT ON ALL EXTERNAL TABLES IN SCHEMA db1.sc1 TO ROLE role1");
9531+
verified_stmt("GRANT USAGE ON ALL FUNCTIONS IN SCHEMA db1.sc1 TO ROLE role1");
95319532
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO a:b");
95329533
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO GROUP group1");
95339534
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST");
@@ -9551,6 +9552,7 @@ fn parse_grant() {
95519552
verified_stmt("GRANT USAGE ON FUNCTION db1.sc1.foo(INT) TO ROLE role1");
95529553
verified_stmt("GRANT ROLE role1 TO ROLE role2");
95539554
verified_stmt("GRANT ROLE role1 TO USER user");
9555+
verified_stmt("GRANT CREATE SCHEMA ON DATABASE db1 TO ROLE role1");
95549556
}
95559557

95569558
#[test]

0 commit comments

Comments
 (0)