yoavcloud commented on code in PR #1501:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1501#discussion_r1835682251


##########
src/parser/mod.rs:
##########
@@ -12315,6 +12310,124 @@ impl<'a> Parser<'a> {
         }
         false
     }
+
+    /// Look for all of the expected keywords in sequence, without consuming 
them
+    fn peek_keywords(&mut self, expected: &[Keyword]) -> bool {
+        let index = self.index;
+        for kw in expected {
+            if !self.parse_keyword(*kw) {
+                self.index = index;
+                return false;
+            }
+        }
+        self.index = index;
+        true
+    }
+
+    fn parse_show_stmt_options(&mut self) -> Result<ShowStatementOptions, 
ParserError> {
+        let show_in;
+        let mut filter_position = None;
+        if self.dialect.supports_show_like_before_in() {
+            if let Some(filter) = self.parse_show_statement_filter()? {
+                filter_position = 
Some(ShowStatementFilterPosition::Infix(filter));
+            }
+            show_in = self.maybe_parse_show_stmt_in()?;
+        } else {
+            show_in = self.maybe_parse_show_stmt_in()?;
+            if let Some(filter) = self.parse_show_statement_filter()? {
+                filter_position = 
Some(ShowStatementFilterPosition::Suffix(filter));
+            }
+        }
+        let starts_with = self.maybe_parse_show_stmt_starts_with()?;
+        let limit = self.maybe_parse_show_stmt_limit()?;
+        let from = self.maybe_parse_show_stmt_from()?;
+        Ok(ShowStatementOptions {
+            filter_position,
+            show_in,
+            starts_with,
+            limit,
+            limit_from: from,
+        })
+    }
+
+    fn maybe_parse_show_stmt_in(&mut self) -> Result<Option<ShowStatementIn>, 
ParserError> {
+        let clause = match self.parse_one_of_keywords(&[Keyword::FROM, 
Keyword::IN]) {
+            Some(Keyword::FROM) => ShowStatementInClause::FROM,
+            Some(Keyword::IN) => ShowStatementInClause::IN,
+            _ => return Ok(None),
+        };
+
+        let (parent_type, parent_name) = match self.parse_one_of_keywords(&[
+            Keyword::ACCOUNT,
+            Keyword::DATABASE,
+            Keyword::SCHEMA,
+            Keyword::TABLE,
+            Keyword::VIEW,
+        ]) {
+            Some(Keyword::DATABASE) if self.peek_keywords(&[Keyword::STARTS, 
Keyword::WITH]) => {
+                (Some(ShowStatementInParentType::Database), None)
+            }
+            Some(Keyword::SCHEMA) if self.peek_keywords(&[Keyword::STARTS, 
Keyword::WITH]) => {
+                (Some(ShowStatementInParentType::Schema), None)
+            }
+            Some(parent_kw) => {
+                let parent_name = match self.parse_object_name(false) {
+                    Ok(n) => Some(n),
+                    _ => None,

Review Comment:
   @iffyio actually, the issue here is that the optional parent name is located 
at the end of the statement. We need to differentiate between SHOW TABLES IN 
DATABASE and SHOW TABLES IN DATABASE db1. The failure to parse the object name 
is the indication.
   
   Do you have a suggestion as to how to handle this case better?



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