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


##########
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,
+                };
+                match parent_kw {
+                    Keyword::ACCOUNT => 
(Some(ShowStatementInParentType::Account), parent_name),
+                    Keyword::DATABASE => 
(Some(ShowStatementInParentType::Database), parent_name),
+                    Keyword::SCHEMA => 
(Some(ShowStatementInParentType::Schema), parent_name),
+                    Keyword::TABLE => (Some(ShowStatementInParentType::Table), 
parent_name),
+                    Keyword::VIEW => (Some(ShowStatementInParentType::View), 
parent_name),
+                    _ => unreachable!(),
+                }
+            }
+            None => {
+                // Parsing MySQL style FROM tbl_name FROM db_name
+                // which is equivalent to FROM tbl_name.db_name
+                let mut parent_name = self.parse_object_name(false)?;
+                if self
+                    .parse_one_of_keywords(&[Keyword::FROM, Keyword::IN])
+                    .is_some()
+                {
+                    parent_name.0.insert(0, self.parse_identifier(false)?);

Review Comment:
   See here for the previous code: 
https://github.com/apache/datafusion-sqlparser-rs/blob/334a5bf354ac964a14f2e2dc3851ed4d853b28d7/src/parser/mod.rs#L9683
   
   It basically transforms the SHOW COLUMNS FROM tbl1 FROM db1 to the canonical 
form SHOW COLUMNS FROM db1.tbl1



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