Skip to content

Commit 970fff0

Browse files
yoavcloudayman-sigma
authored andcommitted
Add support for GRANT on some common Snowflake objects (apache#1699)
1 parent 0272c5f commit 970fff0

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
@@ -5902,12 +5902,20 @@ pub enum GrantObjects {
59025902
AllSequencesInSchema { schemas: Vec<ObjectName> },
59035903
/// Grant privileges on `ALL TABLES IN SCHEMA <schema_name> [, ...]`
59045904
AllTablesInSchema { schemas: Vec<ObjectName> },
5905+
/// Grant privileges on specific databases
5906+
Databases(Vec<ObjectName>),
59055907
/// Grant privileges on specific schemas
59065908
Schemas(Vec<ObjectName>),
59075909
/// Grant privileges on specific sequences
59085910
Sequences(Vec<ObjectName>),
59095911
/// Grant privileges on specific tables
59105912
Tables(Vec<ObjectName>),
5913+
/// Grant privileges on specific views
5914+
Views(Vec<ObjectName>),
5915+
/// Grant privileges on specific warehouses
5916+
Warehouses(Vec<ObjectName>),
5917+
/// Grant privileges on specific integrations
5918+
Integrations(Vec<ObjectName>),
59115919
}
59125920

59135921
impl fmt::Display for GrantObjects {
@@ -5916,12 +5924,24 @@ impl fmt::Display for GrantObjects {
59165924
GrantObjects::Sequences(sequences) => {
59175925
write!(f, "SEQUENCE {}", display_comma_separated(sequences))
59185926
}
5927+
GrantObjects::Databases(databases) => {
5928+
write!(f, "DATABASE {}", display_comma_separated(databases))
5929+
}
59195930
GrantObjects::Schemas(schemas) => {
59205931
write!(f, "SCHEMA {}", display_comma_separated(schemas))
59215932
}
59225933
GrantObjects::Tables(tables) => {
59235934
write!(f, "{}", display_comma_separated(tables))
59245935
}
5936+
GrantObjects::Views(views) => {
5937+
write!(f, "VIEW {}", display_comma_separated(views))
5938+
}
5939+
GrantObjects::Warehouses(warehouses) => {
5940+
write!(f, "WAREHOUSE {}", display_comma_separated(warehouses))
5941+
}
5942+
GrantObjects::Integrations(integrations) => {
5943+
write!(f, "INTEGRATION {}", display_comma_separated(integrations))
5944+
}
59255945
GrantObjects::AllSequencesInSchema { schemas } => {
59265946
write!(
59275947
f,

src/parser/mod.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -12149,13 +12149,24 @@ impl<'a> Parser<'a> {
1214912149
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
1215012150
}
1215112151
} else {
12152-
let object_type =
12153-
self.parse_one_of_keywords(&[Keyword::SEQUENCE, Keyword::SCHEMA, Keyword::TABLE]);
12152+
let object_type = self.parse_one_of_keywords(&[
12153+
Keyword::SEQUENCE,
12154+
Keyword::DATABASE,
12155+
Keyword::SCHEMA,
12156+
Keyword::TABLE,
12157+
Keyword::VIEW,
12158+
Keyword::WAREHOUSE,
12159+
Keyword::INTEGRATION,
12160+
]);
1215412161
let objects =
1215512162
self.parse_comma_separated(|p| p.parse_object_name_with_wildcards(false, true));
1215612163
match object_type {
12164+
Some(Keyword::DATABASE) => GrantObjects::Databases(objects?),
1215712165
Some(Keyword::SCHEMA) => GrantObjects::Schemas(objects?),
1215812166
Some(Keyword::SEQUENCE) => GrantObjects::Sequences(objects?),
12167+
Some(Keyword::WAREHOUSE) => GrantObjects::Warehouses(objects?),
12168+
Some(Keyword::INTEGRATION) => GrantObjects::Integrations(objects?),
12169+
Some(Keyword::VIEW) => GrantObjects::Views(objects?),
1215912170
Some(Keyword::TABLE) | None => GrantObjects::Tables(objects?),
1216012171
_ => unreachable!(),
1216112172
}

tests/sqlparser_common.rs

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

87858789
#[test]

0 commit comments

Comments
 (0)