Skip to content

Commit cd52535

Browse files
yoavcloudayman-sigma
authored andcommitted
Snowflake: Support GRANT CREATE SCHEMA GRANT .. ON ALL FUNCTIONS IN SCHEMA (apache#1964)
1 parent eb9cbe6 commit cd52535

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/ast/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6800,6 +6800,7 @@ pub enum ActionCreateObjectType {
68006800
OrganiationListing,
68016801
ReplicationGroup,
68026802
Role,
6803+
Schema,
68036804
Share,
68046805
User,
68056806
Warehouse,
@@ -6821,6 +6822,7 @@ impl fmt::Display for ActionCreateObjectType {
68216822
ActionCreateObjectType::OrganiationListing => write!(f, "ORGANIZATION LISTING"),
68226823
ActionCreateObjectType::ReplicationGroup => write!(f, "REPLICATION GROUP"),
68236824
ActionCreateObjectType::Role => write!(f, "ROLE"),
6825+
ActionCreateObjectType::Schema => write!(f, "SCHEMA"),
68246826
ActionCreateObjectType::Share => write!(f, "SHARE"),
68256827
ActionCreateObjectType::User => write!(f, "USER"),
68266828
ActionCreateObjectType::Warehouse => write!(f, "WAREHOUSE"),
@@ -7058,6 +7060,8 @@ pub enum GrantObjects {
70587060
AllMaterializedViewsInSchema { schemas: Vec<ObjectName> },
70597061
/// Grant privileges on `ALL EXTERNAL TABLES IN SCHEMA <schema_name> [, ...]`
70607062
AllExternalTablesInSchema { schemas: Vec<ObjectName> },
7063+
/// Grant privileges on `ALL FUNCTIONS IN SCHEMA <schema_name> [, ...]`
7064+
AllFunctionsInSchema { schemas: Vec<ObjectName> },
70617065
/// Grant privileges on `FUTURE SCHEMAS IN DATABASE <database_name> [, ...]`
70627066
FutureSchemasInDatabase { databases: Vec<ObjectName> },
70637067
/// Grant privileges on `FUTURE TABLES IN SCHEMA <schema_name> [, ...]`
@@ -7178,6 +7182,13 @@ impl fmt::Display for GrantObjects {
71787182
display_comma_separated(schemas)
71797183
)
71807184
}
7185+
GrantObjects::AllFunctionsInSchema { schemas } => {
7186+
write!(
7187+
f,
7188+
"ALL FUNCTIONS IN SCHEMA {}",
7189+
display_comma_separated(schemas)
7190+
)
7191+
}
71817192
GrantObjects::FutureSchemasInDatabase { databases } => {
71827193
write!(
71837194
f,

src/parser/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14140,6 +14140,15 @@ impl<'a> Parser<'a> {
1414014140
Some(GrantObjects::AllMaterializedViewsInSchema {
1414114141
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
1414214142
})
14143+
} else if self.parse_keywords(&[
14144+
Keyword::ALL,
14145+
Keyword::FUNCTIONS,
14146+
Keyword::IN,
14147+
Keyword::SCHEMA,
14148+
]) {
14149+
Some(GrantObjects::AllFunctionsInSchema {
14150+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
14151+
})
1414314152
} else if self.parse_keywords(&[
1414414153
Keyword::FUTURE,
1414514154
Keyword::SCHEMAS,
@@ -14446,6 +14455,8 @@ impl<'a> Parser<'a> {
1444614455
Some(ActionCreateObjectType::Integration)
1444714456
} else if self.parse_keyword(Keyword::ROLE) {
1444814457
Some(ActionCreateObjectType::Role)
14458+
} else if self.parse_keyword(Keyword::SCHEMA) {
14459+
Some(ActionCreateObjectType::Schema)
1444914460
} else if self.parse_keyword(Keyword::SHARE) {
1445014461
Some(ActionCreateObjectType::Share)
1445114462
} 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
@@ -9529,6 +9529,7 @@ fn parse_grant() {
95299529
verified_stmt("GRANT SELECT ON ALL VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
95309530
verified_stmt("GRANT SELECT ON ALL MATERIALIZED VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
95319531
verified_stmt("GRANT SELECT ON ALL EXTERNAL TABLES IN SCHEMA db1.sc1 TO ROLE role1");
9532+
verified_stmt("GRANT USAGE ON ALL FUNCTIONS IN SCHEMA db1.sc1 TO ROLE role1");
95329533
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO a:b");
95339534
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO GROUP group1");
95349535
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST");
@@ -9552,6 +9553,7 @@ fn parse_grant() {
95529553
verified_stmt("GRANT USAGE ON FUNCTION db1.sc1.foo(INT) TO ROLE role1");
95539554
verified_stmt("GRANT ROLE role1 TO ROLE role2");
95549555
verified_stmt("GRANT ROLE role1 TO USER user");
9556+
verified_stmt("GRANT CREATE SCHEMA ON DATABASE db1 TO ROLE role1");
95559557
}
95569558

95579559
#[test]

0 commit comments

Comments
 (0)