Add support for GRANT on some common Snowflake objects (#1699)

This commit is contained in:
Yoav Cohen 2025-02-03 08:21:17 +01:00 committed by GitHub
parent c3256a80d7
commit 906f395341
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 2 deletions

View file

@ -5884,12 +5884,20 @@ pub enum GrantObjects {
AllSequencesInSchema { schemas: Vec<ObjectName> },
/// Grant privileges on `ALL TABLES IN SCHEMA <schema_name> [, ...]`
AllTablesInSchema { schemas: Vec<ObjectName> },
/// Grant privileges on specific databases
Databases(Vec<ObjectName>),
/// Grant privileges on specific schemas
Schemas(Vec<ObjectName>),
/// Grant privileges on specific sequences
Sequences(Vec<ObjectName>),
/// Grant privileges on specific tables
Tables(Vec<ObjectName>),
/// Grant privileges on specific views
Views(Vec<ObjectName>),
/// Grant privileges on specific warehouses
Warehouses(Vec<ObjectName>),
/// Grant privileges on specific integrations
Integrations(Vec<ObjectName>),
}
impl fmt::Display for GrantObjects {
@ -5898,12 +5906,24 @@ impl fmt::Display for GrantObjects {
GrantObjects::Sequences(sequences) => {
write!(f, "SEQUENCE {}", display_comma_separated(sequences))
}
GrantObjects::Databases(databases) => {
write!(f, "DATABASE {}", display_comma_separated(databases))
}
GrantObjects::Schemas(schemas) => {
write!(f, "SCHEMA {}", display_comma_separated(schemas))
}
GrantObjects::Tables(tables) => {
write!(f, "{}", display_comma_separated(tables))
}
GrantObjects::Views(views) => {
write!(f, "VIEW {}", display_comma_separated(views))
}
GrantObjects::Warehouses(warehouses) => {
write!(f, "WAREHOUSE {}", display_comma_separated(warehouses))
}
GrantObjects::Integrations(integrations) => {
write!(f, "INTEGRATION {}", display_comma_separated(integrations))
}
GrantObjects::AllSequencesInSchema { schemas } => {
write!(
f,

View file

@ -12139,13 +12139,24 @@ impl<'a> Parser<'a> {
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
}
} else {
let object_type =
self.parse_one_of_keywords(&[Keyword::SEQUENCE, Keyword::SCHEMA, Keyword::TABLE]);
let object_type = self.parse_one_of_keywords(&[
Keyword::SEQUENCE,
Keyword::DATABASE,
Keyword::SCHEMA,
Keyword::TABLE,
Keyword::VIEW,
Keyword::WAREHOUSE,
Keyword::INTEGRATION,
]);
let objects =
self.parse_comma_separated(|p| p.parse_object_name_with_wildcards(false, true));
match object_type {
Some(Keyword::DATABASE) => GrantObjects::Databases(objects?),
Some(Keyword::SCHEMA) => GrantObjects::Schemas(objects?),
Some(Keyword::SEQUENCE) => GrantObjects::Sequences(objects?),
Some(Keyword::WAREHOUSE) => GrantObjects::Warehouses(objects?),
Some(Keyword::INTEGRATION) => GrantObjects::Integrations(objects?),
Some(Keyword::VIEW) => GrantObjects::Views(objects?),
Some(Keyword::TABLE) | None => GrantObjects::Tables(objects?),
_ => unreachable!(),
}

View file

@ -8779,6 +8779,10 @@ fn parse_grant() {
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO a:b");
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO GROUP group1");
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST");
verified_stmt("GRANT USAGE ON DATABASE db1 TO ROLE role1");
verified_stmt("GRANT USAGE ON WAREHOUSE wh1 TO ROLE role1");
verified_stmt("GRANT OWNERSHIP ON INTEGRATION int1 TO ROLE role1");
verified_stmt("GRANT SELECT ON VIEW view1 TO ROLE role1");
}
#[test]