mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 15:04:04 +00:00
Add support for GRANT on some common Snowflake objects (#1699)
This commit is contained in:
parent
c3256a80d7
commit
906f395341
3 changed files with 37 additions and 2 deletions
|
@ -5884,12 +5884,20 @@ pub enum GrantObjects {
|
||||||
AllSequencesInSchema { schemas: Vec<ObjectName> },
|
AllSequencesInSchema { schemas: Vec<ObjectName> },
|
||||||
/// Grant privileges on `ALL TABLES IN SCHEMA <schema_name> [, ...]`
|
/// Grant privileges on `ALL TABLES IN SCHEMA <schema_name> [, ...]`
|
||||||
AllTablesInSchema { schemas: Vec<ObjectName> },
|
AllTablesInSchema { schemas: Vec<ObjectName> },
|
||||||
|
/// Grant privileges on specific databases
|
||||||
|
Databases(Vec<ObjectName>),
|
||||||
/// Grant privileges on specific schemas
|
/// Grant privileges on specific schemas
|
||||||
Schemas(Vec<ObjectName>),
|
Schemas(Vec<ObjectName>),
|
||||||
/// Grant privileges on specific sequences
|
/// Grant privileges on specific sequences
|
||||||
Sequences(Vec<ObjectName>),
|
Sequences(Vec<ObjectName>),
|
||||||
/// Grant privileges on specific tables
|
/// Grant privileges on specific tables
|
||||||
Tables(Vec<ObjectName>),
|
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 {
|
impl fmt::Display for GrantObjects {
|
||||||
|
@ -5898,12 +5906,24 @@ impl fmt::Display for GrantObjects {
|
||||||
GrantObjects::Sequences(sequences) => {
|
GrantObjects::Sequences(sequences) => {
|
||||||
write!(f, "SEQUENCE {}", display_comma_separated(sequences))
|
write!(f, "SEQUENCE {}", display_comma_separated(sequences))
|
||||||
}
|
}
|
||||||
|
GrantObjects::Databases(databases) => {
|
||||||
|
write!(f, "DATABASE {}", display_comma_separated(databases))
|
||||||
|
}
|
||||||
GrantObjects::Schemas(schemas) => {
|
GrantObjects::Schemas(schemas) => {
|
||||||
write!(f, "SCHEMA {}", display_comma_separated(schemas))
|
write!(f, "SCHEMA {}", display_comma_separated(schemas))
|
||||||
}
|
}
|
||||||
GrantObjects::Tables(tables) => {
|
GrantObjects::Tables(tables) => {
|
||||||
write!(f, "{}", display_comma_separated(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 } => {
|
GrantObjects::AllSequencesInSchema { schemas } => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
|
|
|
@ -12139,13 +12139,24 @@ impl<'a> Parser<'a> {
|
||||||
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
|
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let object_type =
|
let object_type = self.parse_one_of_keywords(&[
|
||||||
self.parse_one_of_keywords(&[Keyword::SEQUENCE, Keyword::SCHEMA, Keyword::TABLE]);
|
Keyword::SEQUENCE,
|
||||||
|
Keyword::DATABASE,
|
||||||
|
Keyword::SCHEMA,
|
||||||
|
Keyword::TABLE,
|
||||||
|
Keyword::VIEW,
|
||||||
|
Keyword::WAREHOUSE,
|
||||||
|
Keyword::INTEGRATION,
|
||||||
|
]);
|
||||||
let objects =
|
let objects =
|
||||||
self.parse_comma_separated(|p| p.parse_object_name_with_wildcards(false, true));
|
self.parse_comma_separated(|p| p.parse_object_name_with_wildcards(false, true));
|
||||||
match object_type {
|
match object_type {
|
||||||
|
Some(Keyword::DATABASE) => GrantObjects::Databases(objects?),
|
||||||
Some(Keyword::SCHEMA) => GrantObjects::Schemas(objects?),
|
Some(Keyword::SCHEMA) => GrantObjects::Schemas(objects?),
|
||||||
Some(Keyword::SEQUENCE) => GrantObjects::Sequences(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?),
|
Some(Keyword::TABLE) | None => GrantObjects::Tables(objects?),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 a:b");
|
||||||
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO GROUP group1");
|
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 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]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue