aharpervc commented on code in PR #1836:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1836#discussion_r2073698163


##########
src/parser/mod.rs:
##########
@@ -13020,14 +13035,18 @@ impl<'a> Parser<'a> {
                 GranteesType::Share
             } else if self.parse_keyword(Keyword::GROUP) {
                 GranteesType::Group
-            } else if self.parse_keyword(Keyword::PUBLIC) {
-                GranteesType::Public
             } else if self.parse_keywords(&[Keyword::DATABASE, Keyword::ROLE]) 
{
                 GranteesType::DatabaseRole
             } else if self.parse_keywords(&[Keyword::APPLICATION, 
Keyword::ROLE]) {
                 GranteesType::ApplicationRole
             } else if self.parse_keyword(Keyword::APPLICATION) {
                 GranteesType::Application
+            } else if self.peek_keyword(Keyword::PUBLIC) {
+                if dialect_of!(self is MsSqlDialect) {
+                    grantee_type
+                } else {
+                    GranteesType::Public
+                }

Review Comment:
   > hmm not sure I followed the intention here, public is represented 
differently for mssql? (we would want to describe that behavior without the 
`dialect_of` macro I think)
   
   My interpretation of the existing code is that "public" is being interpreted 
as a keyword. With SQL Server, "public" is a built in role 
([ref](https://learn.microsoft.com/en-us/sql/relational-databases/security/authentication-access/database-level-roles?view=sql-server-ver16#public-database-role))
   
   From a parsing perspective, there wouldn't be any difference between a 
built-in role & any other role. The consideration here is "keyword" vs "not 
keyword". The additional test case examples here cover this behavior.
   
   Put simply, this (and GRANT) should be able to parse normally:
   
   ```mssql
   DENY SELECT ON my_table TO public
   ```
   
   ---
   
   With regards to the code, what is the preferred way to implement this 
behavior? Brainstorming...
   1. Use `dialect_of`
   2. Copy/paste this entire method into the dialect so it's fully duplicated 
except for this keyword
   3. Implement a dialect function to describe "tokens that are listed as 
keywords but should be treated as identifiers", or similar, and then it's blank 
for most dialects but returns "public" for SQL Server
   4. Something else...?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to