Skip to content

Commit d7bc609

Browse files
yoavcloudVedin
authored andcommitted
Add support for GRANT on some common Snowflake objects (apache#1699)
1 parent 5f4be68 commit d7bc609

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/ast/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6064,12 +6064,20 @@ pub enum GrantObjects {
60646064
AllSequencesInSchema { schemas: Vec<ObjectName> },
60656065
/// Grant privileges on `ALL TABLES IN SCHEMA <schema_name> [, ...]`
60666066
AllTablesInSchema { schemas: Vec<ObjectName> },
6067+
/// Grant privileges on specific databases
6068+
Databases(Vec<ObjectName>),
60676069
/// Grant privileges on specific schemas
60686070
Schemas(Vec<ObjectName>),
60696071
/// Grant privileges on specific sequences
60706072
Sequences(Vec<ObjectName>),
60716073
/// Grant privileges on specific tables
60726074
Tables(Vec<ObjectName>),
6075+
/// Grant privileges on specific views
6076+
Views(Vec<ObjectName>),
6077+
/// Grant privileges on specific warehouses
6078+
Warehouses(Vec<ObjectName>),
6079+
/// Grant privileges on specific integrations
6080+
Integrations(Vec<ObjectName>),
60736081
}
60746082

60756083
impl fmt::Display for GrantObjects {
@@ -6078,12 +6086,24 @@ impl fmt::Display for GrantObjects {
60786086
GrantObjects::Sequences(sequences) => {
60796087
write!(f, "SEQUENCE {}", display_comma_separated(sequences))
60806088
}
6089+
GrantObjects::Databases(databases) => {
6090+
write!(f, "DATABASE {}", display_comma_separated(databases))
6091+
}
60816092
GrantObjects::Schemas(schemas) => {
60826093
write!(f, "SCHEMA {}", display_comma_separated(schemas))
60836094
}
60846095
GrantObjects::Tables(tables) => {
60856096
write!(f, "{}", display_comma_separated(tables))
60866097
}
6098+
GrantObjects::Views(views) => {
6099+
write!(f, "VIEW {}", display_comma_separated(views))
6100+
}
6101+
GrantObjects::Warehouses(warehouses) => {
6102+
write!(f, "WAREHOUSE {}", display_comma_separated(warehouses))
6103+
}
6104+
GrantObjects::Integrations(integrations) => {
6105+
write!(f, "INTEGRATION {}", display_comma_separated(integrations))
6106+
}
60876107
GrantObjects::AllSequencesInSchema { schemas } => {
60886108
write!(
60896109
f,

src/parser/mod.rs

Lines changed: 13 additions & 2 deletions
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

Lines changed: 4 additions & 0 deletions
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)