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/22 02:14:06 UTC
[shardingsphere] branch master updated: Support FOR Clause of SELECT Statement (#16990)
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 00b77f7a767 Support FOR Clause of SELECT Statement (#16990)
00b77f7a767 is described below
commit 00b77f7a767c76f249b4b6adea8147ff564e73d7
Author: Thanoshan MV <48...@users.noreply.github.com>
AuthorDate: Fri Apr 22 07:44:00 2022 +0530
Support FOR Clause of SELECT Statement (#16990)
---
.../main/antlr4/imports/sqlserver/DMLStatement.g4 | 20 +++++-
.../antlr4/imports/sqlserver/SQLServerKeyword.g4 | 56 +++++++++++++++++
.../src/main/resources/case/dml/select.xml | 72 ++++++++++++++++++++++
.../main/resources/sql/supported/dml/select.xml | 3 +
4 files changed, 150 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 e03ea250b49..cd0e30cc537 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?
+ : SELECT duplicateSpecification? projections fromClause? whereClause? groupByClause? havingClause? orderByClause? forClause?
;
duplicateSpecification
@@ -228,3 +228,21 @@ useHitName
| SQ_ QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_n SQ_
| SQ_ QUERY_PLAN_PROFILE SQ_
;
+
+forClause
+ : FOR (BROWSE | forXmlClause | forJsonClause)
+ ;
+
+forXmlClause
+ : XML ((RAW (LP_ stringLiterals RP_)? | AUTO) (commonDirectivesForXml (COMMA_ (XMLDATA | XMLSCHEMA (LP_ stringLiterals RP_)?))? (COMMA_ ELEMENTS (XSINIL | ABSENT)?)?)?
+ | EXPLICIT (commonDirectivesForXml (COMMA_ XMLDATA)?)?
+ | PATH (LP_ stringLiterals RP_)? (commonDirectivesForXml (COMMA_ ELEMENTS (XSINIL | ABSENT)?)?)?)
+ ;
+
+commonDirectivesForXml
+ : (COMMA_ BINARY BASE64)? (COMMA_ TYPE)? (COMMA_ ROOT (LP_ stringLiterals RP_)?)?
+ ;
+
+forJsonClause
+ : JSON ((AUTO | PATH) ((COMMA_ ROOT (LP_ stringLiterals RP_)?)? (COMMA_ INCLUDE_NULL_VALUES)? (COMMA_ WITHOUT_ARRAY_WRAPPER)?)?)
+ ;
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 62741176acd..79b5d921352 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
@@ -1850,3 +1850,59 @@ REVERT
COOKIE
: C O O K I E
;
+
+BROWSE
+ : B R O W S E
+ ;
+
+RAW
+ : R A W
+ ;
+
+XMLDATA
+ : X M L D A T A
+ ;
+
+XMLSCHEMA
+ : X M L S C H E M A
+ ;
+
+ELEMENTS
+ : E L E M E N T S
+ ;
+
+XSINIL
+ : X S I N I L
+ ;
+
+ABSENT
+ : A B S E N T
+ ;
+
+EXPLICIT
+ : E X P L I C I T
+ ;
+
+PATH
+ : P A T H
+ ;
+
+BASE64
+ : B A S E '6' '4'
+ ;
+
+ROOT
+ : R O O T
+ ;
+
+JSON
+ : J S O N
+ ;
+
+INCLUDE_NULL_VALUES
+ : I N C L U D E UL_ N U L L UL_ V A L U E S
+ ;
+
+WITHOUT_ARRAY_WRAPPER
+ : W I T H O U T UL_ A R R A Y UL_ W R A P P E R
+ ;
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 42f2af0aaa1..157b3e9a24f 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
@@ -4265,4 +4265,76 @@
<expression-projection text="binary'abc" alias="a" start-index="7" stop-index="24" />
</projections>
</select>
+
+ <select sql-case-id="select_with_for_xml_clause">
+ <from>
+ <join-table>
+ <left>
+ <simple-table name="t_order" alias="o" start-index="44" stop-index="52" />
+ </left>
+ <right>
+ <simple-table name="t_order_item" alias="i" start-index="65" stop-index="78" />
+ </right>
+ <on-condition>
+ <binary-operation-expression start-index="83" stop-index="103">
+ <left>
+ <column name="user_id" start-index="83" stop-index="91">
+ <owner name="o" start-index="83" stop-index="83" />
+ </column>
+ </left>
+ <operator>=</operator>
+ <right>
+ <column name="user_id" start-index="95" stop-index="103">
+ <owner name="i" start-index="95" stop-index="95" />
+ </column>
+ </right>
+ </binary-operation-expression>
+ </on-condition>
+ </join-table>
+ </from>
+ <projections start-index="7" stop-index="37">
+ <column-projection name="order_id" start-index="7" stop-index="16">
+ <owner name="o" start-index="7" stop-index="7" />
+ </column-projection>
+ <column-projection name="status" start-index="19" stop-index="26">
+ <owner name="o" start-index="19" stop-index="19" />
+ </column-projection>
+ <column-projection name="item_id" start-index="29" stop-index="37">
+ <owner name="i" start-index="29" stop-index="29" />
+ </column-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="select_with_for_xml_clause_with_directive">
+ <from>
+ <simple-table name="t_order" start-index="28" stop-index="34" />
+ </from>
+ <projections start-index="7" stop-index="21">
+ <column-projection name="user_id" start-index="7" stop-index="13"/>
+ <column-projection name="status" start-index="16" stop-index="21"/>
+ </projections>
+ <where start-index="36" stop-index="53">
+ <expr>
+ <binary-operation-expression start-index="42" stop-index="53">
+ <left>
+ <column name="order_id" start-index="42" stop-index="49" />
+ </left>
+ <operator>=</operator>
+ <right>
+ <literal-expression value="1" start-index="53" stop-index="53" />
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </where>
+ </select>
+
+ <select sql-case-id="select_with_for_json_clause">
+ <from>
+ <simple-table name="t_order" start-index="29" stop-index="35" />
+ </from>
+ <projections start-index="7" stop-index="22">
+ <column-projection name="order_id" start-index="7" stop-index="14"/>
+ <column-projection name="status" start-index="17" stop-index="22"/>
+ </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 e51b4ffc9d7..03f2ed04a79 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
@@ -122,4 +122,7 @@
<sql-case id="select_with_underscore_charset" value="SELECT _code,_a FROM t_order" db-types="MySQL" />
<sql-case id="select_table_with_capacity_unit_charset" value="SELECT T.USER_NO FROM T_RATION_INFO T" db-types="Oracle" />
<sql-case id="select_with_character_charset" value="SELECT _binary 'abc' as a" db-types="MySQL" />
+ <sql-case id="select_with_for_xml_clause" value="SELECT o.order_id, o.status, i.item_id FROM t_order o INNER JOIN t_order_item i ON o.user_id = i.user_id FOR XML AUTO" db-types="SQLServer" />
+ <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-cases>