This is an automated email from the ASF dual-hosted git repository.

iffyio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 906f3953 Add support for GRANT on some common Snowflake objects (#1699)
906f3953 is described below

commit 906f39534176f389b85e485044ca85d77caccaac
Author: Yoav Cohen <[email protected]>
AuthorDate: Mon Feb 3 08:21:17 2025 +0100

    Add support for GRANT on some common Snowflake objects (#1699)
---
 src/ast/mod.rs            | 20 ++++++++++++++++++++
 src/parser/mod.rs         | 15 +++++++++++++--
 tests/sqlparser_common.rs |  4 ++++
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index bccc580b..c0d3ea57 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -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,
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index ca858c42..7d2d407d 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -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!(),
             }
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index 6113a370..643ac357 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to