Skip to content

Commit 906f395

Browse files
authored
Add support for GRANT on some common Snowflake objects (#1699)
1 parent c3256a8 commit 906f395

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/ast/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -5884,12 +5884,20 @@ pub enum GrantObjects {
58845884
AllSequencesInSchema { schemas: Vec<ObjectName> },
58855885
/// Grant privileges on `ALL TABLES IN SCHEMA <schema_name> [, ...]`
58865886
AllTablesInSchema { schemas: Vec<ObjectName> },
5887+
/// Grant privileges on specific databases
5888+
Databases(Vec<ObjectName>),
58875889
/// Grant privileges on specific schemas
58885890
Schemas(Vec<ObjectName>),
58895891
/// Grant privileges on specific sequences
58905892
Sequences(Vec<ObjectName>),
58915893
/// Grant privileges on specific tables
58925894
Tables(Vec<ObjectName>),
5895+
/// Grant privileges on specific views
5896+
Views(Vec<ObjectName>),
5897+
/// Grant privileges on specific warehouses
5898+
Warehouses(Vec<ObjectName>),
5899+
/// Grant privileges on specific integrations
5900+
Integrations(Vec<ObjectName>),
58935901
}
58945902

58955903
impl fmt::Display for GrantObjects {
@@ -5898,12 +5906,24 @@ impl fmt::Display for GrantObjects {
58985906
GrantObjects::Sequences(sequences) => {
58995907
write!(f, "SEQUENCE {}", display_comma_separated(sequences))
59005908
}
5909+
GrantObjects::Databases(databases) => {
5910+
write!(f, "DATABASE {}", display_comma_separated(databases))
5911+
}
59015912
GrantObjects::Schemas(schemas) => {
59025913
write!(f, "SCHEMA {}", display_comma_separated(schemas))
59035914
}
59045915
GrantObjects::Tables(tables) => {
59055916
write!(f, "{}", display_comma_separated(tables))
59065917
}
5918+
GrantObjects::Views(views) => {
5919+
write!(f, "VIEW {}", display_comma_separated(views))
5920+
}
5921+
GrantObjects::Warehouses(warehouses) => {
5922+
write!(f, "WAREHOUSE {}", display_comma_separated(warehouses))
5923+
}
5924+
GrantObjects::Integrations(integrations) => {
5925+
write!(f, "INTEGRATION {}", display_comma_separated(integrations))
5926+
}
59075927
GrantObjects::AllSequencesInSchema { schemas } => {
59085928
write!(
59095929
f,

src/parser/mod.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -12139,13 +12139,24 @@ impl<'a> Parser<'a> {
1213912139
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
1214012140
}
1214112141
} else {
12142-
let object_type =
12143-
self.parse_one_of_keywords(&[Keyword::SEQUENCE, Keyword::SCHEMA, Keyword::TABLE]);
12142+
let object_type = self.parse_one_of_keywords(&[
12143+
Keyword::SEQUENCE,
12144+
Keyword::DATABASE,
12145+
Keyword::SCHEMA,
12146+
Keyword::TABLE,
12147+
Keyword::VIEW,
12148+
Keyword::WAREHOUSE,
12149+
Keyword::INTEGRATION,
12150+
]);
1214412151
let objects =
1214512152
self.parse_comma_separated(|p| p.parse_object_name_with_wildcards(false, true));
1214612153
match object_type {
12154+
Some(Keyword::DATABASE) => GrantObjects::Databases(objects?),
1214712155
Some(Keyword::SCHEMA) => GrantObjects::Schemas(objects?),
1214812156
Some(Keyword::SEQUENCE) => GrantObjects::Sequences(objects?),
12157+
Some(Keyword::WAREHOUSE) => GrantObjects::Warehouses(objects?),
12158+
Some(Keyword::INTEGRATION) => GrantObjects::Integrations(objects?),
12159+
Some(Keyword::VIEW) => GrantObjects::Views(objects?),
1214912160
Some(Keyword::TABLE) | None => GrantObjects::Tables(objects?),
1215012161
_ => unreachable!(),
1215112162
}

tests/sqlparser_common.rs

+4
Original file line numberDiff line numberDiff line change
@@ -8779,6 +8779,10 @@ fn parse_grant() {
87798779
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO a:b");
87808780
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO GROUP group1");
87818781
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST");
8782+
verified_stmt("GRANT USAGE ON DATABASE db1 TO ROLE role1");
8783+
verified_stmt("GRANT USAGE ON WAREHOUSE wh1 TO ROLE role1");
8784+
verified_stmt("GRANT OWNERSHIP ON INTEGRATION int1 TO ROLE role1");
8785+
verified_stmt("GRANT SELECT ON VIEW view1 TO ROLE role1");
87828786
}
87838787

87848788
#[test]

0 commit comments

Comments
 (0)