Skip to content

Commit f2fba48

Browse files
authored
Add support for several Snowflake grant statements (#1922)
1 parent cf9e504 commit f2fba48

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

src/ast/mod.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6928,12 +6928,24 @@ pub enum GrantObjects {
69286928
AllSequencesInSchema { schemas: Vec<ObjectName> },
69296929
/// Grant privileges on `ALL TABLES IN SCHEMA <schema_name> [, ...]`
69306930
AllTablesInSchema { schemas: Vec<ObjectName> },
6931+
/// Grant privileges on `ALL VIEWS IN SCHEMA <schema_name> [, ...]`
6932+
AllViewsInSchema { schemas: Vec<ObjectName> },
6933+
/// Grant privileges on `ALL MATERIALIZED VIEWS IN SCHEMA <schema_name> [, ...]`
6934+
AllMaterializedViewsInSchema { schemas: Vec<ObjectName> },
6935+
/// Grant privileges on `ALL EXTERNAL TABLES IN SCHEMA <schema_name> [, ...]`
6936+
AllExternalTablesInSchema { schemas: Vec<ObjectName> },
69316937
/// Grant privileges on `FUTURE SCHEMAS IN DATABASE <database_name> [, ...]`
69326938
FutureSchemasInDatabase { databases: Vec<ObjectName> },
69336939
/// Grant privileges on `FUTURE TABLES IN SCHEMA <schema_name> [, ...]`
69346940
FutureTablesInSchema { schemas: Vec<ObjectName> },
69356941
/// Grant privileges on `FUTURE VIEWS IN SCHEMA <schema_name> [, ...]`
69366942
FutureViewsInSchema { schemas: Vec<ObjectName> },
6943+
/// Grant privileges on `FUTURE EXTERNAL TABLES IN SCHEMA <schema_name> [, ...]`
6944+
FutureExternalTablesInSchema { schemas: Vec<ObjectName> },
6945+
/// Grant privileges on `FUTURE MATERIALIZED VIEWS IN SCHEMA <schema_name> [, ...]`
6946+
FutureMaterializedViewsInSchema { schemas: Vec<ObjectName> },
6947+
/// Grant privileges on `FUTURE SEQUENCES IN SCHEMA <schema_name> [, ...]`
6948+
FutureSequencesInSchema { schemas: Vec<ObjectName> },
69376949
/// Grant privileges on specific databases
69386950
Databases(Vec<ObjectName>),
69396951
/// Grant privileges on specific schemas
@@ -7002,6 +7014,27 @@ impl fmt::Display for GrantObjects {
70027014
display_comma_separated(schemas)
70037015
)
70047016
}
7017+
GrantObjects::AllExternalTablesInSchema { schemas } => {
7018+
write!(
7019+
f,
7020+
"ALL EXTERNAL TABLES IN SCHEMA {}",
7021+
display_comma_separated(schemas)
7022+
)
7023+
}
7024+
GrantObjects::AllViewsInSchema { schemas } => {
7025+
write!(
7026+
f,
7027+
"ALL VIEWS IN SCHEMA {}",
7028+
display_comma_separated(schemas)
7029+
)
7030+
}
7031+
GrantObjects::AllMaterializedViewsInSchema { schemas } => {
7032+
write!(
7033+
f,
7034+
"ALL MATERIALIZED VIEWS IN SCHEMA {}",
7035+
display_comma_separated(schemas)
7036+
)
7037+
}
70057038
GrantObjects::FutureSchemasInDatabase { databases } => {
70067039
write!(
70077040
f,
@@ -7016,13 +7049,34 @@ impl fmt::Display for GrantObjects {
70167049
display_comma_separated(schemas)
70177050
)
70187051
}
7052+
GrantObjects::FutureExternalTablesInSchema { schemas } => {
7053+
write!(
7054+
f,
7055+
"FUTURE EXTERNAL TABLES IN SCHEMA {}",
7056+
display_comma_separated(schemas)
7057+
)
7058+
}
70197059
GrantObjects::FutureViewsInSchema { schemas } => {
70207060
write!(
70217061
f,
70227062
"FUTURE VIEWS IN SCHEMA {}",
70237063
display_comma_separated(schemas)
70247064
)
70257065
}
7066+
GrantObjects::FutureMaterializedViewsInSchema { schemas } => {
7067+
write!(
7068+
f,
7069+
"FUTURE MATERIALIZED VIEWS IN SCHEMA {}",
7070+
display_comma_separated(schemas)
7071+
)
7072+
}
7073+
GrantObjects::FutureSequencesInSchema { schemas } => {
7074+
write!(
7075+
f,
7076+
"FUTURE SEQUENCES IN SCHEMA {}",
7077+
display_comma_separated(schemas)
7078+
)
7079+
}
70267080
GrantObjects::ResourceMonitors(objects) => {
70277081
write!(f, "RESOURCE MONITOR {}", display_comma_separated(objects))
70287082
}

src/parser/mod.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13901,6 +13901,35 @@ impl<'a> Parser<'a> {
1390113901
Some(GrantObjects::AllTablesInSchema {
1390213902
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
1390313903
})
13904+
} else if self.parse_keywords(&[
13905+
Keyword::ALL,
13906+
Keyword::EXTERNAL,
13907+
Keyword::TABLES,
13908+
Keyword::IN,
13909+
Keyword::SCHEMA,
13910+
]) {
13911+
Some(GrantObjects::AllExternalTablesInSchema {
13912+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
13913+
})
13914+
} else if self.parse_keywords(&[
13915+
Keyword::ALL,
13916+
Keyword::VIEWS,
13917+
Keyword::IN,
13918+
Keyword::SCHEMA,
13919+
]) {
13920+
Some(GrantObjects::AllViewsInSchema {
13921+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
13922+
})
13923+
} else if self.parse_keywords(&[
13924+
Keyword::ALL,
13925+
Keyword::MATERIALIZED,
13926+
Keyword::VIEWS,
13927+
Keyword::IN,
13928+
Keyword::SCHEMA,
13929+
]) {
13930+
Some(GrantObjects::AllMaterializedViewsInSchema {
13931+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
13932+
})
1390413933
} else if self.parse_keywords(&[
1390513934
Keyword::FUTURE,
1390613935
Keyword::SCHEMAS,
@@ -13919,6 +13948,16 @@ impl<'a> Parser<'a> {
1391913948
Some(GrantObjects::FutureTablesInSchema {
1392013949
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
1392113950
})
13951+
} else if self.parse_keywords(&[
13952+
Keyword::FUTURE,
13953+
Keyword::EXTERNAL,
13954+
Keyword::TABLES,
13955+
Keyword::IN,
13956+
Keyword::SCHEMA,
13957+
]) {
13958+
Some(GrantObjects::FutureExternalTablesInSchema {
13959+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
13960+
})
1392213961
} else if self.parse_keywords(&[
1392313962
Keyword::FUTURE,
1392413963
Keyword::VIEWS,
@@ -13928,6 +13967,16 @@ impl<'a> Parser<'a> {
1392813967
Some(GrantObjects::FutureViewsInSchema {
1392913968
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
1393013969
})
13970+
} else if self.parse_keywords(&[
13971+
Keyword::FUTURE,
13972+
Keyword::MATERIALIZED,
13973+
Keyword::VIEWS,
13974+
Keyword::IN,
13975+
Keyword::SCHEMA,
13976+
]) {
13977+
Some(GrantObjects::FutureMaterializedViewsInSchema {
13978+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
13979+
})
1393113980
} else if self.parse_keywords(&[
1393213981
Keyword::ALL,
1393313982
Keyword::SEQUENCES,
@@ -13937,6 +13986,15 @@ impl<'a> Parser<'a> {
1393713986
Some(GrantObjects::AllSequencesInSchema {
1393813987
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
1393913988
})
13989+
} else if self.parse_keywords(&[
13990+
Keyword::FUTURE,
13991+
Keyword::SEQUENCES,
13992+
Keyword::IN,
13993+
Keyword::SCHEMA,
13994+
]) {
13995+
Some(GrantObjects::FutureSequencesInSchema {
13996+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
13997+
})
1394013998
} else if self.parse_keywords(&[Keyword::RESOURCE, Keyword::MONITOR]) {
1394113999
Some(GrantObjects::ResourceMonitors(self.parse_comma_separated(
1394214000
|p| p.parse_object_name_with_wildcards(false, true),

tests/sqlparser_common.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9434,6 +9434,9 @@ fn parse_grant() {
94349434
verified_stmt("GRANT SELECT ON ALL TABLES IN SCHEMA db1.sc1 TO APPLICATION role1");
94359435
verified_stmt("GRANT SELECT ON ALL TABLES IN SCHEMA db1.sc1 TO APPLICATION ROLE role1");
94369436
verified_stmt("GRANT SELECT ON ALL TABLES IN SCHEMA db1.sc1 TO SHARE share1");
9437+
verified_stmt("GRANT SELECT ON ALL VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
9438+
verified_stmt("GRANT SELECT ON ALL MATERIALIZED VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
9439+
verified_stmt("GRANT SELECT ON ALL EXTERNAL TABLES IN SCHEMA db1.sc1 TO ROLE role1");
94379440
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO a:b");
94389441
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO GROUP group1");
94399442
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST");
@@ -9447,7 +9450,10 @@ fn parse_grant() {
94479450
.verified_stmt("GRANT SELECT ON [my_table] TO [public]");
94489451
verified_stmt("GRANT SELECT ON FUTURE SCHEMAS IN DATABASE db1 TO ROLE role1");
94499452
verified_stmt("GRANT SELECT ON FUTURE TABLES IN SCHEMA db1.sc1 TO ROLE role1");
9453+
verified_stmt("GRANT SELECT ON FUTURE EXTERNAL TABLES IN SCHEMA db1.sc1 TO ROLE role1");
94509454
verified_stmt("GRANT SELECT ON FUTURE VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
9455+
verified_stmt("GRANT SELECT ON FUTURE MATERIALIZED VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
9456+
verified_stmt("GRANT SELECT ON FUTURE SEQUENCES IN SCHEMA db1.sc1 TO ROLE role1");
94519457
}
94529458

94539459
#[test]

0 commit comments

Comments
 (0)