Skip to content

Commit 5189c90

Browse files
Snowflake: parse ALL/FUTURE … IN DATABASE grant targets, STAGE/FILE FORMAT objects, WRITE + CREATE TABLE privileges
1 parent 6d1428e commit 5189c90

2 files changed

Lines changed: 198 additions & 0 deletions

File tree

src/ast/mod.rs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8376,6 +8376,8 @@ pub enum Action {
83768376

83778377
/// Read access.
83788378
Read,
8379+
/// Write access.
8380+
Write,
83798381
/// Read session-level access.
83808382
ReadSession,
83818383
/// References with optional column list.
@@ -8469,6 +8471,7 @@ impl fmt::Display for Action {
84698471
Action::Ownership => f.write_str("OWNERSHIP")?,
84708472
Action::PurchaseDataExchangeListing => f.write_str("PURCHASE DATA EXCHANGE LISTING")?,
84718473
Action::Read => f.write_str("READ")?,
8474+
Action::Write => f.write_str("WRITE")?,
84728475
Action::ReadSession => f.write_str("READ SESSION")?,
84738476
Action::References { .. } => f.write_str("REFERENCES")?,
84748477
Action::Replicate => f.write_str("REPLICATE")?,
@@ -8537,6 +8540,8 @@ pub enum ActionCreateObjectType {
85378540
Schema,
85388541
/// A share object.
85398542
Share,
8543+
/// A table object.
8544+
Table,
85408545
/// A user object.
85418546
User,
85428547
/// A warehouse object.
@@ -8563,6 +8568,7 @@ impl fmt::Display for ActionCreateObjectType {
85638568
ActionCreateObjectType::Role => write!(f, "ROLE"),
85648569
ActionCreateObjectType::Schema => write!(f, "SCHEMA"),
85658570
ActionCreateObjectType::Share => write!(f, "SHARE"),
8571+
ActionCreateObjectType::Table => write!(f, "TABLE"),
85668572
ActionCreateObjectType::User => write!(f, "USER"),
85678573
ActionCreateObjectType::Warehouse => write!(f, "WAREHOUSE"),
85688574
}
@@ -8895,6 +8901,46 @@ pub enum GrantObjects {
88958901
/// The target schema names.
88968902
schemas: Vec<ObjectName>,
88978903
},
8904+
/// Grant privileges on `ALL SCHEMAS IN DATABASE <database_name> [, ...]`
8905+
AllSchemasInDatabase {
8906+
/// The target database names.
8907+
databases: Vec<ObjectName>,
8908+
},
8909+
/// Grant privileges on `ALL TABLES IN DATABASE <database_name> [, ...]`
8910+
AllTablesInDatabase {
8911+
/// The target database names.
8912+
databases: Vec<ObjectName>,
8913+
},
8914+
/// Grant privileges on `ALL STAGES IN SCHEMA <schema_name> [, ...]`
8915+
AllStagesInSchema {
8916+
/// The target schema names.
8917+
schemas: Vec<ObjectName>,
8918+
},
8919+
/// Grant privileges on `ALL FILE FORMATS IN SCHEMA <schema_name> [, ...]`
8920+
AllFileFormatsInSchema {
8921+
/// The target schema names.
8922+
schemas: Vec<ObjectName>,
8923+
},
8924+
/// Grant privileges on `FUTURE TABLES IN DATABASE <database_name> [, ...]`
8925+
FutureTablesInDatabase {
8926+
/// The target database names.
8927+
databases: Vec<ObjectName>,
8928+
},
8929+
/// Grant privileges on `FUTURE STAGES IN SCHEMA <schema_name> [, ...]`
8930+
FutureStagesInSchema {
8931+
/// The target schema names.
8932+
schemas: Vec<ObjectName>,
8933+
},
8934+
/// Grant privileges on `FUTURE FILE FORMATS IN SCHEMA <schema_name> [, ...]`
8935+
FutureFileFormatsInSchema {
8936+
/// The target schema names.
8937+
schemas: Vec<ObjectName>,
8938+
},
8939+
/// Grant privileges on `FUTURE FUNCTIONS IN SCHEMA <schema_name> [, ...]`
8940+
FutureFunctionsInSchema {
8941+
/// The target schema names.
8942+
schemas: Vec<ObjectName>,
8943+
},
88988944
/// Grant privileges on specific databases
88998945
Databases(Vec<ObjectName>),
89008946
/// Grant privileges on specific schemas
@@ -8913,6 +8959,10 @@ pub enum GrantObjects {
89138959
ResourceMonitors(Vec<ObjectName>),
89148960
/// Grant privileges on users
89158961
Users(Vec<ObjectName>),
8962+
/// Grant privileges on specific stages
8963+
Stages(Vec<ObjectName>),
8964+
/// Grant privileges on specific file formats
8965+
FileFormats(Vec<ObjectName>),
89168966
/// Grant privileges on compute pools
89178967
ComputePools(Vec<ObjectName>),
89188968
/// Grant privileges on connections
@@ -9056,12 +9106,74 @@ impl fmt::Display for GrantObjects {
90569106
display_comma_separated(schemas)
90579107
)
90589108
}
9109+
GrantObjects::AllSchemasInDatabase { databases } => {
9110+
write!(
9111+
f,
9112+
"ALL SCHEMAS IN DATABASE {}",
9113+
display_comma_separated(databases)
9114+
)
9115+
}
9116+
GrantObjects::AllTablesInDatabase { databases } => {
9117+
write!(
9118+
f,
9119+
"ALL TABLES IN DATABASE {}",
9120+
display_comma_separated(databases)
9121+
)
9122+
}
9123+
GrantObjects::AllStagesInSchema { schemas } => {
9124+
write!(
9125+
f,
9126+
"ALL STAGES IN SCHEMA {}",
9127+
display_comma_separated(schemas)
9128+
)
9129+
}
9130+
GrantObjects::AllFileFormatsInSchema { schemas } => {
9131+
write!(
9132+
f,
9133+
"ALL FILE FORMATS IN SCHEMA {}",
9134+
display_comma_separated(schemas)
9135+
)
9136+
}
9137+
GrantObjects::FutureTablesInDatabase { databases } => {
9138+
write!(
9139+
f,
9140+
"FUTURE TABLES IN DATABASE {}",
9141+
display_comma_separated(databases)
9142+
)
9143+
}
9144+
GrantObjects::FutureStagesInSchema { schemas } => {
9145+
write!(
9146+
f,
9147+
"FUTURE STAGES IN SCHEMA {}",
9148+
display_comma_separated(schemas)
9149+
)
9150+
}
9151+
GrantObjects::FutureFileFormatsInSchema { schemas } => {
9152+
write!(
9153+
f,
9154+
"FUTURE FILE FORMATS IN SCHEMA {}",
9155+
display_comma_separated(schemas)
9156+
)
9157+
}
9158+
GrantObjects::FutureFunctionsInSchema { schemas } => {
9159+
write!(
9160+
f,
9161+
"FUTURE FUNCTIONS IN SCHEMA {}",
9162+
display_comma_separated(schemas)
9163+
)
9164+
}
90599165
GrantObjects::ResourceMonitors(objects) => {
90609166
write!(f, "RESOURCE MONITOR {}", display_comma_separated(objects))
90619167
}
90629168
GrantObjects::Users(objects) => {
90639169
write!(f, "USER {}", display_comma_separated(objects))
90649170
}
9171+
GrantObjects::Stages(objects) => {
9172+
write!(f, "STAGE {}", display_comma_separated(objects))
9173+
}
9174+
GrantObjects::FileFormats(objects) => {
9175+
write!(f, "FILE FORMAT {}", display_comma_separated(objects))
9176+
}
90659177
GrantObjects::ComputePools(objects) => {
90669178
write!(f, "COMPUTE POOL {}", display_comma_separated(objects))
90679179
}

src/parser/mod.rs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18150,6 +18150,80 @@ impl<'a> Parser<'a> {
1815018150
Some(GrantObjects::FutureSequencesInSchema {
1815118151
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
1815218152
})
18153+
} else if self.parse_keywords(&[
18154+
Keyword::ALL,
18155+
Keyword::SCHEMAS,
18156+
Keyword::IN,
18157+
Keyword::DATABASE,
18158+
]) {
18159+
Some(GrantObjects::AllSchemasInDatabase {
18160+
databases: self.parse_comma_separated(|p| p.parse_object_name(false))?,
18161+
})
18162+
} else if self.parse_keywords(&[
18163+
Keyword::ALL,
18164+
Keyword::TABLES,
18165+
Keyword::IN,
18166+
Keyword::DATABASE,
18167+
]) {
18168+
Some(GrantObjects::AllTablesInDatabase {
18169+
databases: self.parse_comma_separated(|p| p.parse_object_name(false))?,
18170+
})
18171+
} else if self.parse_keywords(&[
18172+
Keyword::ALL,
18173+
Keyword::STAGES,
18174+
Keyword::IN,
18175+
Keyword::SCHEMA,
18176+
]) {
18177+
Some(GrantObjects::AllStagesInSchema {
18178+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
18179+
})
18180+
} else if self.parse_keywords(&[
18181+
Keyword::ALL,
18182+
Keyword::FILE,
18183+
Keyword::FORMATS,
18184+
Keyword::IN,
18185+
Keyword::SCHEMA,
18186+
]) {
18187+
Some(GrantObjects::AllFileFormatsInSchema {
18188+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
18189+
})
18190+
} else if self.parse_keywords(&[
18191+
Keyword::FUTURE,
18192+
Keyword::TABLES,
18193+
Keyword::IN,
18194+
Keyword::DATABASE,
18195+
]) {
18196+
Some(GrantObjects::FutureTablesInDatabase {
18197+
databases: self.parse_comma_separated(|p| p.parse_object_name(false))?,
18198+
})
18199+
} else if self.parse_keywords(&[
18200+
Keyword::FUTURE,
18201+
Keyword::STAGES,
18202+
Keyword::IN,
18203+
Keyword::SCHEMA,
18204+
]) {
18205+
Some(GrantObjects::FutureStagesInSchema {
18206+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
18207+
})
18208+
} else if self.parse_keywords(&[
18209+
Keyword::FUTURE,
18210+
Keyword::FILE,
18211+
Keyword::FORMATS,
18212+
Keyword::IN,
18213+
Keyword::SCHEMA,
18214+
]) {
18215+
Some(GrantObjects::FutureFileFormatsInSchema {
18216+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
18217+
})
18218+
} else if self.parse_keywords(&[
18219+
Keyword::FUTURE,
18220+
Keyword::FUNCTIONS,
18221+
Keyword::IN,
18222+
Keyword::SCHEMA,
18223+
]) {
18224+
Some(GrantObjects::FutureFunctionsInSchema {
18225+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
18226+
})
1815318227
} else if self.parse_keywords(&[Keyword::RESOURCE, Keyword::MONITOR]) {
1815418228
Some(GrantObjects::ResourceMonitors(
1815518229
self.parse_comma_separated(|p| p.parse_object_name(false))?,
@@ -18170,6 +18244,14 @@ impl<'a> Parser<'a> {
1817018244
Some(GrantObjects::ExternalVolumes(
1817118245
self.parse_comma_separated(|p| p.parse_object_name(false))?,
1817218246
))
18247+
} else if self.parse_keywords(&[Keyword::FILE, Keyword::FORMAT]) {
18248+
Some(GrantObjects::FileFormats(
18249+
self.parse_comma_separated(|p| p.parse_object_name(false))?,
18250+
))
18251+
} else if self.parse_keyword(Keyword::STAGE) {
18252+
Some(GrantObjects::Stages(
18253+
self.parse_comma_separated(|p| p.parse_object_name(false))?,
18254+
))
1817318255
} else {
1817418256
let object_type = self.parse_one_of_keywords(&[
1817518257
Keyword::SEQUENCE,
@@ -18334,6 +18416,8 @@ impl<'a> Parser<'a> {
1833418416
})
1833518417
} else if self.parse_keyword(Keyword::READ) {
1833618418
Ok(Action::Read)
18419+
} else if self.parse_keyword(Keyword::WRITE) {
18420+
Ok(Action::Write)
1833718421
} else if self.parse_keyword(Keyword::REPLICATE) {
1833818422
Ok(Action::Replicate)
1833918423
} else if self.parse_keyword(Keyword::ROLE) {
@@ -18400,6 +18484,8 @@ impl<'a> Parser<'a> {
1840018484
Some(ActionCreateObjectType::Schema)
1840118485
} else if self.parse_keyword(Keyword::SHARE) {
1840218486
Some(ActionCreateObjectType::Share)
18487+
} else if self.parse_keyword(Keyword::TABLE) {
18488+
Some(ActionCreateObjectType::Table)
1840318489
} else if self.parse_keyword(Keyword::USER) {
1840418490
Some(ActionCreateObjectType::User)
1840518491
} else if self.parse_keyword(Keyword::WAREHOUSE) {

0 commit comments

Comments
 (0)