LucaCappelletti94 commented on code in PR #2508:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2508#discussion_r4095602599


##########
src/parser/mod.rs:
##########
@@ -4091,6 +4091,15 @@ impl<'a> Parser<'a> {
                         Ok(Expr::IsUnknown(Box::new(expr)))
                     } else if self.parse_keywords(&[Keyword::NOT, 
Keyword::UNKNOWN]) {
                         Ok(Expr::IsNotUnknown(Box::new(expr)))
+                    } else if let Some(negated) = if 
dialect.supports_xml_expressions() {
+                        self.parse_is_document_predicate()
+                    } else {
+                        None
+                    } {
+                        Ok(Expr::IsDocument {
+                            expr: Box::new(expr),
+                            negated,
+                        })

Review Comment:
   You should match `DOCUMENT` as a keyword with 
`parse_keyword`/`parse_keywords`, like the neighbouring `UNKNOWN` and `JSON` 
arms. Ofc add the `keywords.rs` entry.
   
   ```suggestion
                       } else if dialect.supports_xml_expressions()
                           && self.parse_keyword(Keyword::DOCUMENT)
                       {
                           Ok(Expr::IsDocument {
                               expr: Box::new(expr),
                               negated: false,
                           })
                       } else if dialect.supports_xml_expressions()
                           && self.parse_keywords(&[Keyword::NOT, 
Keyword::DOCUMENT])
                       {
                           Ok(Expr::IsDocument {
                               expr: Box::new(expr),
                               negated: true,
                           })
   ```



##########
src/parser/mod.rs:
##########
@@ -4752,6 +4761,16 @@ impl<'a> Parser<'a> {
         }
     }
 
+    fn parse_unquoted_word(&mut self, expected: &str) -> bool {
+        match &self.peek_token_ref().token {
+            Token::Word(w) if w.quote_style.is_none() && 
w.value.eq_ignore_ascii_case(expected) => {
+                self.advance_token();
+                true
+            }
+            _ => false,
+        }
+    }
+

Review Comment:
   You could drop `parse_unquoted_word`, since 
`parse_keyword(Keyword::DOCUMENT)` covers it. The tokenizer already gives 
quoted words `Keyword::NoKeyword`.
   
   ```suggestion
   ```



##########
src/parser/mod.rs:
##########
@@ -4109,7 +4118,7 @@ impl<'a> Parser<'a> {
                         Ok(is_normalized)
                     } else {
                         self.expected_ref(
-                            "[NOT] NULL | TRUE | FALSE | DISTINCT | [NOT] JSON 
[VALUE | SCALAR | ARRAY | OBJECT] [WITH | WITHOUT UNIQUE [KEYS]] | [form] 
NORMALIZED FROM after IS",
+                            "[NOT] NULL | TRUE | FALSE | DISTINCT | [NOT] 
DOCUMENT | [NOT] JSON [VALUE | SCALAR | ARRAY | OBJECT] [WITH | WITHOUT UNIQUE 
[KEYS]] | [form] NORMALIZED FROM after IS",

Review Comment:
   You should keep `[NOT] DOCUMENT` out of this message, which every dialect 
shares.
   
   ```suggestion
                               "[NOT] NULL | TRUE | FALSE | DISTINCT | [NOT] 
JSON [VALUE | SCALAR | ARRAY | OBJECT] [WITH | WITHOUT UNIQUE [KEYS]] | [form] 
NORMALIZED FROM after IS",
   ```



##########
src/parser/mod.rs:
##########
@@ -12742,6 +12761,20 @@ impl<'a> Parser<'a> {
         })
     }
 
+    fn parse_is_document_predicate(&mut self) -> Option<bool> {
+        if self.parse_unquoted_word("document") {
+            return Some(false);
+        }
+
+        let start_index = self.index;
+        if self.parse_keyword(Keyword::NOT) && 
self.parse_unquoted_word("document") {
+            Some(true)
+        } else {
+            self.index = start_index;
+            None
+        }
+    }
+

Review Comment:
   You could drop `parse_is_document_predicate` along with the manual 
`self.index` rewind, since `parse_keywords` handles both.
   
   ```suggestion
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to