Skip to content

Add xmlnamespace support mssql - #2361

Open
kfirSatori wants to merge 4 commits into
apache:mainfrom
SatoriCyber:add_xmlnamespace_support_mssql
Open

Add xmlnamespace support mssql#2361
kfirSatori wants to merge 4 commits into
apache:mainfrom
SatoriCyber:add_xmlnamespace_support_mssql

Conversation

@kfirSatori

Copy link
Copy Markdown

Added support to parse xmlnamespace in mssql, for queris like:
WITH XMLNAMESPACES ('urn:test' AS ns) SELECT 1 AS [ns:Value] FOR XML PATH('ns:Root');

@kfirSatori

Copy link
Copy Markdown
Author

Hi @iffyio CAn you please help with this PR as well?

Comment thread tests/sqlparser_mssql.rs Outdated
Comment on lines +2928 to +2947
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();
} No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's merge these and have them use verified_stmt

Comment thread src/parser/mod.rs Outdated
Comment on lines +14116 to +14127
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the impl looks odd, is it parsing and dropping the content?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, I missed the addition to AST fixed now

Comment thread src/dialect/mssql.rs
}
}

fn supports_with_xmlnamespaces_clause(&self) -> bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we include a link to the documentation of this syntax?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iffyio Added documentation link

Comment thread tests/sqlparser_mssql.rs

ms().parse_sql_statements(sql).unwrap();

ms().verified_stmt("WITH XMLNAMESPACES ('urn:test' AS ns) SELECT 1 AS [ns:Value] FOR XML PATH('ns:Root')");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merged tests and used verifies_stmt() @iffyio

@@ -0,0 +1,133 @@
/// Test to verify XMLNAMESPACES parsing and AST storage

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I don't think we should introduce a new file for this test. Also let's merge the tests and used either verified_stmt or one_statement_parses_to in tests as I mentioned in the previous review. one simplification of the tests introduced here is to drop the AST assertions, the PR doesn't introduce a new node so its overkill to have each test expiclitly assert the full AST. please have the tests follow existing conventions (this is introducing some println and manual display assertions patterns and is unclear why that's needed)

Comment thread src/ast/query.rs
Comment on lines 757 to +760
/// The list of CTEs declared by this `WITH` clause.
pub cte_tables: Vec<Cte>,
/// Optional XML namespace definitions (`WITH XMLNAMESPACES (...)`).
pub xml_namespaces: Vec<XmlNamespaceDefinition>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feature looks similar to what was done here for clickhouse CSEs, such that I'm thinking we essentially want to introduce this feature in that style instead. is xml_namespaces looks like a regular expression (CSE) so that the enum changes might even be verbatim (similarly for the dialect method name)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed i use the WITH keyword as done with cte_tables, i hope i understood what you have meant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants