You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/04/28 00:07:22 UTC

[shardingsphere] branch master updated: Support for XmlNamespaces Clause of SQLServer SELECT Statement (#17157)

This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 05af4af29d9 Support for XmlNamespaces Clause of SQLServer SELECT Statement (#17157)
05af4af29d9 is described below

commit 05af4af29d9da0a43e406b6166f2bbe2322ca0fe
Author: Thanoshan MV <48...@users.noreply.github.com>
AuthorDate: Thu Apr 28 05:37:00 2022 +0530

    Support for XmlNamespaces Clause of SQLServer SELECT Statement (#17157)
---
 .../main/antlr4/imports/sqlserver/DMLStatement.g4  | 26 +++++++++++++++++++++-
 .../antlr4/imports/sqlserver/SQLServerKeyword.g4   |  4 ++++
 .../src/main/resources/case/dml/select.xml         | 20 +++++++++++++++++
 .../main/resources/sql/supported/dml/select.xml    |  2 ++
 4 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4
index cd0e30cc537..6d11977c8d1 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4
@@ -81,7 +81,7 @@ aggregationClause
     ;
 
 selectClause
-    : SELECT duplicateSpecification? projections fromClause? whereClause? groupByClause? havingClause? orderByClause? forClause?
+    : selectWithClause? SELECT duplicateSpecification? projections fromClause? whereClause? groupByClause? havingClause? orderByClause? forClause?
     ;
 
 duplicateSpecification
@@ -246,3 +246,27 @@ commonDirectivesForXml
 forJsonClause
     : JSON ((AUTO | PATH) ((COMMA_ ROOT (LP_ stringLiterals RP_)?)? (COMMA_ INCLUDE_NULL_VALUES)? (COMMA_ WITHOUT_ARRAY_WRAPPER)?)?)
     ;
+
+selectWithClause
+    : WITH (xmlNamespacesClause COMMA_?)?
+    ;
+
+xmlNamespacesClause
+    : XMLNAMESPACES LP_ xmlNamespaceDeclarationItem (COMMA_ xmlNamespaceDeclarationItem)* RP_
+    ;
+
+xmlNamespaceDeclarationItem
+    : xmlNamespaceUri AS xmlNamespacePrefix | xmlDefaultNamespaceDeclarationItem
+    ;
+
+xmlNamespaceUri
+    : stringLiterals
+    ;
+
+xmlNamespacePrefix
+    : identifier
+    ;
+
+xmlDefaultNamespaceDeclarationItem
+    : DEFAULT xmlNamespaceUri
+    ;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerKeyword.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerKeyword.g4
index 79b5d921352..b942380b097 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerKeyword.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerKeyword.g4
@@ -1906,3 +1906,7 @@ INCLUDE_NULL_VALUES
 WITHOUT_ARRAY_WRAPPER
     : W I T H O U T UL_ A R R A Y UL_ W R A P P E R
     ;
+
+XMLNAMESPACES
+    : X M L N A M E S P A C E S
+    ;
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
index bdda02e03ec..5bc815ade87 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
@@ -4348,4 +4348,24 @@
             </column-projection>
         </projections>
     </select>
+
+    <select sql-case-id="select_with_xml_namespaces_clause">
+        <from>
+            <simple-table name="t_order" start-index="97" stop-index="103" />
+        </from>
+        <projections start-index="41" stop-index="90">
+            <column-projection name="order_id" alias="ns1:order_id" start-index="41" stop-index="66"/>
+            <column-projection name="status" alias="ns1:status" start-index="69" stop-index="90"/>
+        </projections>
+    </select>
+
+    <select sql-case-id="select_with_xml_default_namespaces_clause">
+        <from>
+            <simple-table name="t_order" start-index="129" stop-index="135" />
+        </from>
+        <projections start-index="73" stop-index="122">
+            <column-projection name="order_id" alias="ns1:order_id" start-index="73" stop-index="98"/>
+            <column-projection name="status" alias="ns1:status" start-index="101" stop-index="122"/>
+        </projections>
+    </select>
 </sql-parser-test-cases>
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/select.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/select.xml
index 0f9c5a11347..0db198430d1 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/select.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/select.xml
@@ -126,4 +126,6 @@
     <sql-case id="select_with_for_xml_clause_with_directive" value="SELECT user_id, status FROM t_order WHERE order_id = 1 FOR XML RAW, ELEMENTS XSINIL" db-types="SQLServer" />
     <sql-case id="select_with_for_json_clause" value="SELECT order_id, status FROM t_order FOR JSON AUTO, INCLUDE_NULL_VALUES" db-types="SQLServer" />
     <sql-case id="select_with_keyword_target" value="SELECT m.target FROM sys_menu m" />
+    <sql-case id="select_with_xml_namespaces_clause" value="WITH XMLNAMESPACES ('uri' AS ns1) SELECT order_id AS 'ns1:order_id', status AS 'ns1:status' FROM t_order FOR XML RAW ('ns1:order'), ELEMENTS" db-types="SQLServer" />
+    <sql-case id="select_with_xml_default_namespaces_clause" value="WITH XMLNAMESPACES ('uri1' AS ns1, 'uri2' AS ns2, DEFAULT 'uri2') SELECT order_id AS 'ns1:order_id', status AS 'ns1:status' FROM t_order FOR XML RAW ('ns1:order'), ELEMENTS XSINIL" db-types="SQLServer" />
 </sql-cases>