Skip to content

Commit e1f8cb2

Browse files
yoavcloudayman-sigma
authored andcommitted
Add support for several Snowflake grant statements (apache#1922)
1 parent f13a8b4 commit e1f8cb2

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

src/ast/mod.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6957,12 +6957,24 @@ pub enum GrantObjects {
69576957
AllSequencesInSchema { schemas: Vec<ObjectName> },
69586958
/// Grant privileges on `ALL TABLES IN SCHEMA <schema_name> [, ...]`
69596959
AllTablesInSchema { schemas: Vec<ObjectName> },
6960+
/// Grant privileges on `ALL VIEWS IN SCHEMA <schema_name> [, ...]`
6961+
AllViewsInSchema { schemas: Vec<ObjectName> },
6962+
/// Grant privileges on `ALL MATERIALIZED VIEWS IN SCHEMA <schema_name> [, ...]`
6963+
AllMaterializedViewsInSchema { schemas: Vec<ObjectName> },
6964+
/// Grant privileges on `ALL EXTERNAL TABLES IN SCHEMA <schema_name> [, ...]`
6965+
AllExternalTablesInSchema { schemas: Vec<ObjectName> },
69606966
/// Grant privileges on `FUTURE SCHEMAS IN DATABASE <database_name> [, ...]`
69616967
FutureSchemasInDatabase { databases: Vec<ObjectName> },
69626968
/// Grant privileges on `FUTURE TABLES IN SCHEMA <schema_name> [, ...]`
69636969
FutureTablesInSchema { schemas: Vec<ObjectName> },
69646970
/// Grant privileges on `FUTURE VIEWS IN SCHEMA <schema_name> [, ...]`
69656971
FutureViewsInSchema { schemas: Vec<ObjectName> },
6972+
/// Grant privileges on `FUTURE EXTERNAL TABLES IN SCHEMA <schema_name> [, ...]`
6973+
FutureExternalTablesInSchema { schemas: Vec<ObjectName> },
6974+
/// Grant privileges on `FUTURE MATERIALIZED VIEWS IN SCHEMA <schema_name> [, ...]`
6975+
FutureMaterializedViewsInSchema { schemas: Vec<ObjectName> },
6976+
/// Grant privileges on `FUTURE SEQUENCES IN SCHEMA <schema_name> [, ...]`
6977+
FutureSequencesInSchema { schemas: Vec<ObjectName> },
69666978
/// Grant privileges on specific databases
69676979
Databases(Vec<ObjectName>),
69686980
/// Grant privileges on specific schemas
@@ -7031,6 +7043,27 @@ impl fmt::Display for GrantObjects {
70317043
display_comma_separated(schemas)
70327044
)
70337045
}
7046+
GrantObjects::AllExternalTablesInSchema { schemas } => {
7047+
write!(
7048+
f,
7049+
"ALL EXTERNAL TABLES IN SCHEMA {}",
7050+
display_comma_separated(schemas)
7051+
)
7052+
}
7053+
GrantObjects::AllViewsInSchema { schemas } => {
7054+
write!(
7055+
f,
7056+
"ALL VIEWS IN SCHEMA {}",
7057+
display_comma_separated(schemas)
7058+
)
7059+
}
7060+
GrantObjects::AllMaterializedViewsInSchema { schemas } => {
7061+
write!(
7062+
f,
7063+
"ALL MATERIALIZED VIEWS IN SCHEMA {}",
7064+
display_comma_separated(schemas)
7065+
)
7066+
}
70347067
GrantObjects::FutureSchemasInDatabase { databases } => {
70357068
write!(
70367069
f,
@@ -7045,13 +7078,34 @@ impl fmt::Display for GrantObjects {
70457078
display_comma_separated(schemas)
70467079
)
70477080
}
7081+
GrantObjects::FutureExternalTablesInSchema { schemas } => {
7082+
write!(
7083+
f,
7084+
"FUTURE EXTERNAL TABLES IN SCHEMA {}",
7085+
display_comma_separated(schemas)
7086+
)
7087+
}
70487088
GrantObjects::FutureViewsInSchema { schemas } => {
70497089
write!(
70507090
f,
70517091
"FUTURE VIEWS IN SCHEMA {}",
70527092
display_comma_separated(schemas)
70537093
)
70547094
}
7095+
GrantObjects::FutureMaterializedViewsInSchema { schemas } => {
7096+
write!(
7097+
f,
7098+
"FUTURE MATERIALIZED VIEWS IN SCHEMA {}",
7099+
display_comma_separated(schemas)
7100+
)
7101+
}
7102+
GrantObjects::FutureSequencesInSchema { schemas } => {
7103+
write!(
7104+
f,
7105+
"FUTURE SEQUENCES IN SCHEMA {}",
7106+
display_comma_separated(schemas)
7107+
)
7108+
}
70557109
GrantObjects::ResourceMonitors(objects) => {
70567110
write!(f, "RESOURCE MONITOR {}", display_comma_separated(objects))
70577111
}

src/parser/mod.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13933,6 +13933,35 @@ impl<'a> Parser<'a> {
1393313933
Some(GrantObjects::AllTablesInSchema {
1393413934
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
1393513935
})
13936+
} else if self.parse_keywords(&[
13937+
Keyword::ALL,
13938+
Keyword::EXTERNAL,
13939+
Keyword::TABLES,
13940+
Keyword::IN,
13941+
Keyword::SCHEMA,
13942+
]) {
13943+
Some(GrantObjects::AllExternalTablesInSchema {
13944+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
13945+
})
13946+
} else if self.parse_keywords(&[
13947+
Keyword::ALL,
13948+
Keyword::VIEWS,
13949+
Keyword::IN,
13950+
Keyword::SCHEMA,
13951+
]) {
13952+
Some(GrantObjects::AllViewsInSchema {
13953+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
13954+
})
13955+
} else if self.parse_keywords(&[
13956+
Keyword::ALL,
13957+
Keyword::MATERIALIZED,
13958+
Keyword::VIEWS,
13959+
Keyword::IN,
13960+
Keyword::SCHEMA,
13961+
]) {
13962+
Some(GrantObjects::AllMaterializedViewsInSchema {
13963+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
13964+
})
1393613965
} else if self.parse_keywords(&[
1393713966
Keyword::FUTURE,
1393813967
Keyword::SCHEMAS,
@@ -13951,6 +13980,16 @@ impl<'a> Parser<'a> {
1395113980
Some(GrantObjects::FutureTablesInSchema {
1395213981
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
1395313982
})
13983+
} else if self.parse_keywords(&[
13984+
Keyword::FUTURE,
13985+
Keyword::EXTERNAL,
13986+
Keyword::TABLES,
13987+
Keyword::IN,
13988+
Keyword::SCHEMA,
13989+
]) {
13990+
Some(GrantObjects::FutureExternalTablesInSchema {
13991+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
13992+
})
1395413993
} else if self.parse_keywords(&[
1395513994
Keyword::FUTURE,
1395613995
Keyword::VIEWS,
@@ -13960,6 +13999,16 @@ impl<'a> Parser<'a> {
1396013999
Some(GrantObjects::FutureViewsInSchema {
1396114000
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
1396214001
})
14002+
} else if self.parse_keywords(&[
14003+
Keyword::FUTURE,
14004+
Keyword::MATERIALIZED,
14005+
Keyword::VIEWS,
14006+
Keyword::IN,
14007+
Keyword::SCHEMA,
14008+
]) {
14009+
Some(GrantObjects::FutureMaterializedViewsInSchema {
14010+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
14011+
})
1396314012
} else if self.parse_keywords(&[
1396414013
Keyword::ALL,
1396514014
Keyword::SEQUENCES,
@@ -13969,6 +14018,15 @@ impl<'a> Parser<'a> {
1396914018
Some(GrantObjects::AllSequencesInSchema {
1397014019
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
1397114020
})
14021+
} else if self.parse_keywords(&[
14022+
Keyword::FUTURE,
14023+
Keyword::SEQUENCES,
14024+
Keyword::IN,
14025+
Keyword::SCHEMA,
14026+
]) {
14027+
Some(GrantObjects::FutureSequencesInSchema {
14028+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
14029+
})
1397214030
} else if self.parse_keywords(&[Keyword::RESOURCE, Keyword::MONITOR]) {
1397314031
Some(GrantObjects::ResourceMonitors(self.parse_comma_separated(
1397414032
|p| p.parse_object_name_with_wildcards(false, true),

tests/sqlparser_common.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9435,6 +9435,9 @@ fn parse_grant() {
94359435
verified_stmt("GRANT SELECT ON ALL TABLES IN SCHEMA db1.sc1 TO APPLICATION role1");
94369436
verified_stmt("GRANT SELECT ON ALL TABLES IN SCHEMA db1.sc1 TO APPLICATION ROLE role1");
94379437
verified_stmt("GRANT SELECT ON ALL TABLES IN SCHEMA db1.sc1 TO SHARE share1");
9438+
verified_stmt("GRANT SELECT ON ALL VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
9439+
verified_stmt("GRANT SELECT ON ALL MATERIALIZED VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
9440+
verified_stmt("GRANT SELECT ON ALL EXTERNAL TABLES IN SCHEMA db1.sc1 TO ROLE role1");
94389441
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO a:b");
94399442
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO GROUP group1");
94409443
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST");
@@ -9448,7 +9451,10 @@ fn parse_grant() {
94489451
.verified_stmt("GRANT SELECT ON [my_table] TO [public]");
94499452
verified_stmt("GRANT SELECT ON FUTURE SCHEMAS IN DATABASE db1 TO ROLE role1");
94509453
verified_stmt("GRANT SELECT ON FUTURE TABLES IN SCHEMA db1.sc1 TO ROLE role1");
9454+
verified_stmt("GRANT SELECT ON FUTURE EXTERNAL TABLES IN SCHEMA db1.sc1 TO ROLE role1");
94519455
verified_stmt("GRANT SELECT ON FUTURE VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
9456+
verified_stmt("GRANT SELECT ON FUTURE MATERIALIZED VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
9457+
verified_stmt("GRANT SELECT ON FUTURE SEQUENCES IN SCHEMA db1.sc1 TO ROLE role1");
94529458
}
94539459

94549460
#[test]

0 commit comments

Comments
 (0)