iffyio commented on code in PR #2361:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2361#discussion_r3621398989
##########
src/parser/mod.rs:
##########
@@ -14108,12 +14108,31 @@ impl<'a> Parser<'a> {
pub fn parse_query(&mut self) -> Result<Box<Query>, ParserError> {
let _guard = self.recursion_counter.try_decrease()?;
let with = if self.parse_keyword(Keyword::WITH) {
- let with_token = self.get_current_token();
- Some(With {
- with_token: with_token.clone().into(),
- recursive: self.parse_keyword(Keyword::RECURSIVE),
- cte_tables: self.parse_comma_separated(Parser::parse_cte)?,
- })
+ let with_token = self.get_current_token().clone();
+ if self.dialect.supports_with_xmlnamespaces_clause()
+ && self.parse_keyword(Keyword::XMLNAMESPACES)
+ {
+ self.expect_token(&Token::LParen)?;
+ let _namespaces =
+
self.parse_comma_separated(Parser::parse_xml_namespace_definition)?;
+ self.expect_token(&Token::RParen)?;
+
+ if self.consume_token(&Token::Comma) {
+ Some(With {
+ with_token: with_token.clone().into(),
+ recursive: self.parse_keyword(Keyword::RECURSIVE),
+ cte_tables:
self.parse_comma_separated(Parser::parse_cte)?,
+ })
+ } else {
+ None
Review Comment:
the impl looks odd, is it parsing and dropping the content?
##########
tests/sqlparser_mssql.rs:
##########
@@ -2923,3 +2923,25 @@ fn parse_mssql_money_constants() {
expr_from_projection(only(&select.projection)),
);
}
+
+#[test]
+fn parse_xmlnamespaces() {
+ let sql = r#"WITH XMLNAMESPACES ('urn:test' AS ns)
+SELECT 1 AS [ns:Value]
+FOR XML PATH('ns:Root');"#;
+
+ ms().parse_sql_statements(sql).unwrap();
+
+}
+
+#[test]
+fn parse_xmlnamespaces_with_cte() {
+ let sql = r#"
+WITH XMLNAMESPACES ('urn:example' AS ns), t AS (
+ SELECT 1 AS id
+)
+SELECT id FROM t
+"#;
+
+ ms().parse_sql_statements(sql).unwrap();
+}
Review Comment:
let's merge these and have them use verified_stmt
##########
src/dialect/mssql.rs:
##########
@@ -248,6 +248,10 @@ impl Dialect for MsSqlDialect {
_ => None,
}
}
+
+ fn supports_with_xmlnamespaces_clause(&self) -> bool {
Review Comment:
can we include a link to the documentation of this syntax?
--
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]