alamb commented on code in PR #1646:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1646#discussion_r1905447833


##########
src/parser/mod.rs:
##########
@@ -10307,11 +10307,67 @@ impl<'a> Parser<'a> {
                 snapshot: None,
                 session: false,
             })
+        } else if self.dialect.supports_set_stmt_without_operator() {
+            self.prev_token();
+            self.parse_set_session_params()
         } else {
             self.expected("equals sign or TO", self.peek_token())
         }
     }
 
+    pub fn parse_set_session_params(&mut self) -> Result<Statement, 
ParserError> {
+        let names = 
self.parse_comma_separated(Parser::parse_set_session_param_name)?;
+
+        let last_name = if let Some(last_name) = names.last() {
+            last_name.to_uppercase()
+        } else {
+            return self.expected("Session param name", self.peek_token());
+        };
+
+        let identity_insert_obj = if last_name == "IDENTITY_INSERT" {
+            Some(self.parse_object_name(false)?)
+        } else {
+            None
+        };
+
+        let offsets_keywords = if last_name == "OFFSETS" {
+            Some(self.parse_comma_separated(|parser| {
+                let next_token = parser.next_token();
+                match &next_token.token {
+                    Token::Word(w) => Ok(w.to_string()),
+                    _ => parser.expected("SQL keyword", next_token),
+                }
+            })?)
+        } else {
+            None
+        };
+
+        let value = self.parse_expr()?.to_string();
+        Ok(Statement::SetSessionParam {
+            names,
+            identity_insert_obj,
+            offsets_keywords,
+            value,
+        })
+    }
+
+    pub fn parse_set_session_param_name(&mut self) -> Result<String, 
ParserError> {
+        if self.parse_keywords(&[Keyword::STATISTICS, Keyword::IO]) {
+            return Ok("STATISTICS IO".to_string());
+        } else if self.parse_keywords(&[Keyword::STATISTICS, Keyword::XML]) {
+            return Ok("STATISTICS XML".to_string());
+        } else if self.parse_keywords(&[Keyword::STATISTICS, 
Keyword::PROFILE]) {
+            return Ok("STATISTICS PROFILE".to_string());
+        } else if self.parse_keywords(&[Keyword::STATISTICS, Keyword::TIME]) {
+            return Ok("STATISTICS TIME".to_string());
+        }
+        let next_token = self.next_token();
+        if let Token::Word(w) = next_token.token {
+            return Ok(w.to_string());
+        }
+        self.expected("Session param name", next_token)

Review Comment:
   maybe it would be nice to list the expected keywords (IO/XML/PROFILE/TIME, 
etc) here



##########
src/parser/mod.rs:
##########
@@ -10307,11 +10307,67 @@ impl<'a> Parser<'a> {
                 snapshot: None,
                 session: false,
             })
+        } else if self.dialect.supports_set_stmt_without_operator() {
+            self.prev_token();
+            self.parse_set_session_params()
         } else {
             self.expected("equals sign or TO", self.peek_token())
         }
     }
 
+    pub fn parse_set_session_params(&mut self) -> Result<Statement, 
ParserError> {
+        let names = 
self.parse_comma_separated(Parser::parse_set_session_param_name)?;
+
+        let last_name = if let Some(last_name) = names.last() {
+            last_name.to_uppercase()
+        } else {
+            return self.expected("Session param name", self.peek_token());
+        };
+
+        let identity_insert_obj = if last_name == "IDENTITY_INSERT" {
+            Some(self.parse_object_name(false)?)
+        } else {
+            None
+        };
+
+        let offsets_keywords = if last_name == "OFFSETS" {
+            Some(self.parse_comma_separated(|parser| {
+                let next_token = parser.next_token();
+                match &next_token.token {
+                    Token::Word(w) => Ok(w.to_string()),
+                    _ => parser.expected("SQL keyword", next_token),
+                }
+            })?)
+        } else {
+            None
+        };
+
+        let value = self.parse_expr()?.to_string();
+        Ok(Statement::SetSessionParam {
+            names,
+            identity_insert_obj,
+            offsets_keywords,
+            value,
+        })
+    }
+
+    pub fn parse_set_session_param_name(&mut self) -> Result<String, 
ParserError> {
+        if self.parse_keywords(&[Keyword::STATISTICS, Keyword::IO]) {

Review Comment:
   Given these are hard coded it seems like it would be cleaner to eventually 
return an enum for what setting was set rather than arbitrary strings that the 
using library needs to parse / interpret
   
   However, I also think we could do that as a follow on PR



-- 
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