mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-07 17:04:59 +00:00
Add support for several Snowflake grant statements (#1922)
This commit is contained in:
parent
cf9e50474e
commit
f2fba48a7a
3 changed files with 118 additions and 0 deletions
|
@ -6928,12 +6928,24 @@ 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 `ALL VIEWS IN SCHEMA <schema_name> [, ...]`
|
||||||
|
AllViewsInSchema { schemas: Vec<ObjectName> },
|
||||||
|
/// Grant privileges on `ALL MATERIALIZED VIEWS IN SCHEMA <schema_name> [, ...]`
|
||||||
|
AllMaterializedViewsInSchema { schemas: Vec<ObjectName> },
|
||||||
|
/// Grant privileges on `ALL EXTERNAL TABLES IN SCHEMA <schema_name> [, ...]`
|
||||||
|
AllExternalTablesInSchema { schemas: Vec<ObjectName> },
|
||||||
/// Grant privileges on `FUTURE SCHEMAS IN DATABASE <database_name> [, ...]`
|
/// Grant privileges on `FUTURE SCHEMAS IN DATABASE <database_name> [, ...]`
|
||||||
FutureSchemasInDatabase { databases: Vec<ObjectName> },
|
FutureSchemasInDatabase { databases: Vec<ObjectName> },
|
||||||
/// Grant privileges on `FUTURE TABLES IN SCHEMA <schema_name> [, ...]`
|
/// Grant privileges on `FUTURE TABLES IN SCHEMA <schema_name> [, ...]`
|
||||||
FutureTablesInSchema { schemas: Vec<ObjectName> },
|
FutureTablesInSchema { schemas: Vec<ObjectName> },
|
||||||
/// Grant privileges on `FUTURE VIEWS IN SCHEMA <schema_name> [, ...]`
|
/// Grant privileges on `FUTURE VIEWS IN SCHEMA <schema_name> [, ...]`
|
||||||
FutureViewsInSchema { schemas: Vec<ObjectName> },
|
FutureViewsInSchema { schemas: Vec<ObjectName> },
|
||||||
|
/// Grant privileges on `FUTURE EXTERNAL TABLES IN SCHEMA <schema_name> [, ...]`
|
||||||
|
FutureExternalTablesInSchema { schemas: Vec<ObjectName> },
|
||||||
|
/// Grant privileges on `FUTURE MATERIALIZED VIEWS IN SCHEMA <schema_name> [, ...]`
|
||||||
|
FutureMaterializedViewsInSchema { schemas: Vec<ObjectName> },
|
||||||
|
/// Grant privileges on `FUTURE SEQUENCES IN SCHEMA <schema_name> [, ...]`
|
||||||
|
FutureSequencesInSchema { schemas: Vec<ObjectName> },
|
||||||
/// Grant privileges on specific databases
|
/// Grant privileges on specific databases
|
||||||
Databases(Vec<ObjectName>),
|
Databases(Vec<ObjectName>),
|
||||||
/// Grant privileges on specific schemas
|
/// Grant privileges on specific schemas
|
||||||
|
@ -7002,6 +7014,27 @@ impl fmt::Display for GrantObjects {
|
||||||
display_comma_separated(schemas)
|
display_comma_separated(schemas)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
GrantObjects::AllExternalTablesInSchema { schemas } => {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"ALL EXTERNAL TABLES IN SCHEMA {}",
|
||||||
|
display_comma_separated(schemas)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
GrantObjects::AllViewsInSchema { schemas } => {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"ALL VIEWS IN SCHEMA {}",
|
||||||
|
display_comma_separated(schemas)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
GrantObjects::AllMaterializedViewsInSchema { schemas } => {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"ALL MATERIALIZED VIEWS IN SCHEMA {}",
|
||||||
|
display_comma_separated(schemas)
|
||||||
|
)
|
||||||
|
}
|
||||||
GrantObjects::FutureSchemasInDatabase { databases } => {
|
GrantObjects::FutureSchemasInDatabase { databases } => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
|
@ -7016,6 +7049,13 @@ impl fmt::Display for GrantObjects {
|
||||||
display_comma_separated(schemas)
|
display_comma_separated(schemas)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
GrantObjects::FutureExternalTablesInSchema { schemas } => {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"FUTURE EXTERNAL TABLES IN SCHEMA {}",
|
||||||
|
display_comma_separated(schemas)
|
||||||
|
)
|
||||||
|
}
|
||||||
GrantObjects::FutureViewsInSchema { schemas } => {
|
GrantObjects::FutureViewsInSchema { schemas } => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
|
@ -7023,6 +7063,20 @@ impl fmt::Display for GrantObjects {
|
||||||
display_comma_separated(schemas)
|
display_comma_separated(schemas)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
GrantObjects::FutureMaterializedViewsInSchema { schemas } => {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"FUTURE MATERIALIZED VIEWS IN SCHEMA {}",
|
||||||
|
display_comma_separated(schemas)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
GrantObjects::FutureSequencesInSchema { schemas } => {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"FUTURE SEQUENCES IN SCHEMA {}",
|
||||||
|
display_comma_separated(schemas)
|
||||||
|
)
|
||||||
|
}
|
||||||
GrantObjects::ResourceMonitors(objects) => {
|
GrantObjects::ResourceMonitors(objects) => {
|
||||||
write!(f, "RESOURCE MONITOR {}", display_comma_separated(objects))
|
write!(f, "RESOURCE MONITOR {}", display_comma_separated(objects))
|
||||||
}
|
}
|
||||||
|
|
|
@ -13901,6 +13901,35 @@ impl<'a> Parser<'a> {
|
||||||
Some(GrantObjects::AllTablesInSchema {
|
Some(GrantObjects::AllTablesInSchema {
|
||||||
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
|
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
|
||||||
})
|
})
|
||||||
|
} else if self.parse_keywords(&[
|
||||||
|
Keyword::ALL,
|
||||||
|
Keyword::EXTERNAL,
|
||||||
|
Keyword::TABLES,
|
||||||
|
Keyword::IN,
|
||||||
|
Keyword::SCHEMA,
|
||||||
|
]) {
|
||||||
|
Some(GrantObjects::AllExternalTablesInSchema {
|
||||||
|
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
|
||||||
|
})
|
||||||
|
} else if self.parse_keywords(&[
|
||||||
|
Keyword::ALL,
|
||||||
|
Keyword::VIEWS,
|
||||||
|
Keyword::IN,
|
||||||
|
Keyword::SCHEMA,
|
||||||
|
]) {
|
||||||
|
Some(GrantObjects::AllViewsInSchema {
|
||||||
|
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
|
||||||
|
})
|
||||||
|
} else if self.parse_keywords(&[
|
||||||
|
Keyword::ALL,
|
||||||
|
Keyword::MATERIALIZED,
|
||||||
|
Keyword::VIEWS,
|
||||||
|
Keyword::IN,
|
||||||
|
Keyword::SCHEMA,
|
||||||
|
]) {
|
||||||
|
Some(GrantObjects::AllMaterializedViewsInSchema {
|
||||||
|
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
|
||||||
|
})
|
||||||
} else if self.parse_keywords(&[
|
} else if self.parse_keywords(&[
|
||||||
Keyword::FUTURE,
|
Keyword::FUTURE,
|
||||||
Keyword::SCHEMAS,
|
Keyword::SCHEMAS,
|
||||||
|
@ -13919,6 +13948,16 @@ impl<'a> Parser<'a> {
|
||||||
Some(GrantObjects::FutureTablesInSchema {
|
Some(GrantObjects::FutureTablesInSchema {
|
||||||
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
|
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
|
||||||
})
|
})
|
||||||
|
} else if self.parse_keywords(&[
|
||||||
|
Keyword::FUTURE,
|
||||||
|
Keyword::EXTERNAL,
|
||||||
|
Keyword::TABLES,
|
||||||
|
Keyword::IN,
|
||||||
|
Keyword::SCHEMA,
|
||||||
|
]) {
|
||||||
|
Some(GrantObjects::FutureExternalTablesInSchema {
|
||||||
|
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
|
||||||
|
})
|
||||||
} else if self.parse_keywords(&[
|
} else if self.parse_keywords(&[
|
||||||
Keyword::FUTURE,
|
Keyword::FUTURE,
|
||||||
Keyword::VIEWS,
|
Keyword::VIEWS,
|
||||||
|
@ -13928,6 +13967,16 @@ impl<'a> Parser<'a> {
|
||||||
Some(GrantObjects::FutureViewsInSchema {
|
Some(GrantObjects::FutureViewsInSchema {
|
||||||
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
|
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
|
||||||
})
|
})
|
||||||
|
} else if self.parse_keywords(&[
|
||||||
|
Keyword::FUTURE,
|
||||||
|
Keyword::MATERIALIZED,
|
||||||
|
Keyword::VIEWS,
|
||||||
|
Keyword::IN,
|
||||||
|
Keyword::SCHEMA,
|
||||||
|
]) {
|
||||||
|
Some(GrantObjects::FutureMaterializedViewsInSchema {
|
||||||
|
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
|
||||||
|
})
|
||||||
} else if self.parse_keywords(&[
|
} else if self.parse_keywords(&[
|
||||||
Keyword::ALL,
|
Keyword::ALL,
|
||||||
Keyword::SEQUENCES,
|
Keyword::SEQUENCES,
|
||||||
|
@ -13937,6 +13986,15 @@ impl<'a> Parser<'a> {
|
||||||
Some(GrantObjects::AllSequencesInSchema {
|
Some(GrantObjects::AllSequencesInSchema {
|
||||||
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
|
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
|
||||||
})
|
})
|
||||||
|
} else if self.parse_keywords(&[
|
||||||
|
Keyword::FUTURE,
|
||||||
|
Keyword::SEQUENCES,
|
||||||
|
Keyword::IN,
|
||||||
|
Keyword::SCHEMA,
|
||||||
|
]) {
|
||||||
|
Some(GrantObjects::FutureSequencesInSchema {
|
||||||
|
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
|
||||||
|
})
|
||||||
} else if self.parse_keywords(&[Keyword::RESOURCE, Keyword::MONITOR]) {
|
} else if self.parse_keywords(&[Keyword::RESOURCE, Keyword::MONITOR]) {
|
||||||
Some(GrantObjects::ResourceMonitors(self.parse_comma_separated(
|
Some(GrantObjects::ResourceMonitors(self.parse_comma_separated(
|
||||||
|p| p.parse_object_name_with_wildcards(false, true),
|
|p| p.parse_object_name_with_wildcards(false, true),
|
||||||
|
|
|
@ -9434,6 +9434,9 @@ fn parse_grant() {
|
||||||
verified_stmt("GRANT SELECT ON ALL TABLES IN SCHEMA db1.sc1 TO APPLICATION role1");
|
verified_stmt("GRANT SELECT ON ALL TABLES IN SCHEMA db1.sc1 TO APPLICATION role1");
|
||||||
verified_stmt("GRANT SELECT ON ALL TABLES IN SCHEMA db1.sc1 TO APPLICATION ROLE role1");
|
verified_stmt("GRANT SELECT ON ALL TABLES IN SCHEMA db1.sc1 TO APPLICATION ROLE role1");
|
||||||
verified_stmt("GRANT SELECT ON ALL TABLES IN SCHEMA db1.sc1 TO SHARE share1");
|
verified_stmt("GRANT SELECT ON ALL TABLES IN SCHEMA db1.sc1 TO SHARE share1");
|
||||||
|
verified_stmt("GRANT SELECT ON ALL VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
|
||||||
|
verified_stmt("GRANT SELECT ON ALL MATERIALIZED VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
|
||||||
|
verified_stmt("GRANT SELECT ON ALL EXTERNAL TABLES IN SCHEMA db1.sc1 TO ROLE role1");
|
||||||
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");
|
||||||
|
@ -9447,7 +9450,10 @@ fn parse_grant() {
|
||||||
.verified_stmt("GRANT SELECT ON [my_table] TO [public]");
|
.verified_stmt("GRANT SELECT ON [my_table] TO [public]");
|
||||||
verified_stmt("GRANT SELECT ON FUTURE SCHEMAS IN DATABASE db1 TO ROLE role1");
|
verified_stmt("GRANT SELECT ON FUTURE SCHEMAS IN DATABASE db1 TO ROLE role1");
|
||||||
verified_stmt("GRANT SELECT ON FUTURE TABLES IN SCHEMA db1.sc1 TO ROLE role1");
|
verified_stmt("GRANT SELECT ON FUTURE TABLES IN SCHEMA db1.sc1 TO ROLE role1");
|
||||||
|
verified_stmt("GRANT SELECT ON FUTURE EXTERNAL TABLES IN SCHEMA db1.sc1 TO ROLE role1");
|
||||||
verified_stmt("GRANT SELECT ON FUTURE VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
|
verified_stmt("GRANT SELECT ON FUTURE VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
|
||||||
|
verified_stmt("GRANT SELECT ON FUTURE MATERIALIZED VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
|
||||||
|
verified_stmt("GRANT SELECT ON FUTURE SEQUENCES IN SCHEMA db1.sc1 TO ROLE role1");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue