BenSatori commented on code in PR #2508:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2508#discussion_r4766806029
##########
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:
Done in 62c2ad58: added `DOCUMENT` to `keywords.rs` and applied the
suggestion as-is. `document` still parses as a plain identifier in all
dialects, and `XMLPARSE(DOCUMENT ...)` is unaffected since it reads the mode
via `parse_identifier`.
##########
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:
Done, `[NOT] DOCUMENT` is out of the shared message (it was also breaking
`parse_is_boolean` after merging main).
##########
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:
Removed. Kept a red test for `IS "document"` to pin the quoted-word
behaviour.
##########
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:
Removed along with the manual rewind. I also merged main and updated the
negative test: SQLite now has a general `IS` operator (`supports_is_operator`),
so it legitimately accepts `x IS DOCUMENT`; the test now excludes those
dialects and asserts the typed `ParserError` for the rest.
--
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]