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 bcc606e0829 Support GROUPING function for mysql (#26915)
bcc606e0829 is described below
commit bcc606e08290a988a565bc88cb741680222aa011
Author: niu niu <[email protected]>
AuthorDate: Thu Jul 13 15:22:06 2023 +0800
Support GROUPING function for mysql (#26915)
* Support GROUPING function for mysql
* Format xml
* Format code
* Format code
* Format code
---
.../src/main/antlr4/imports/mysql/BaseRule.g4 | 6 +++-
.../parser/src/main/resources/case/dml/select.xml | 34 ++++++++++++++++++----
.../main/resources/sql/supported/dml/select.xml | 1 +
3 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4
b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4
index ff972a8a107..c5d113cdcc2 100644
--- a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4
+++ b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4
@@ -988,13 +988,17 @@ frameBetween
specialFunction
: groupConcatFunction | windowFunction | castFunction | convertFunction |
positionFunction | substringFunction | extractFunction
- | charFunction | trimFunction | weightStringFunction | valuesFunction |
currentUserFunction
+ | charFunction | trimFunction | weightStringFunction | valuesFunction |
currentUserFunction | groupingFunction
;
currentUserFunction
: CURRENT_USER (LP_ RP_)?
;
+groupingFunction
+ : GROUPING LP_ expr (COMMA_ expr)* RP_
+ ;
+
groupConcatFunction
: GROUP_CONCAT LP_ distinct? (expr (COMMA_ expr)* | ASTERISK_)?
(orderByClause)? (SEPARATOR expr)? RP_
;
diff --git a/test/it/parser/src/main/resources/case/dml/select.xml
b/test/it/parser/src/main/resources/case/dml/select.xml
index 3264f29901f..a8b286cbfa9 100644
--- a/test/it/parser/src/main/resources/case/dml/select.xml
+++ b/test/it/parser/src/main/resources/case/dml/select.xml
@@ -47,6 +47,30 @@
</projections>
</select>
+ <select sql-case-id="select_distinct_with_grouping_function">
+ <from>
+ <simple-table name="t1" start-index="24" stop-index="25" />
+ </from>
+ <projections start-index="16" stop-index="17" distinct-row="true">
+ <column-projection name="f1" start-index="16" stop-index="17" />
+ </projections>
+ <group-by>
+ <column-item name="f1" order-direction="ASC" start-index="36"
stop-index="37" />
+ </group-by>
+ <order-by>
+ <column-item name="f1" order-direction="ASC" start-index="60"
stop-index="61" />
+ <expression-item start-index="64" stop-index="86"
expression="ANY_VALUE(GROUPING(f1))">
+ <expr>
+ <function start-index="64" stop-index="86"
text="ANY_VALUE(GROUPING(f1))" function-name="ANY_VALUE">
+ <parameter>
+ <function start-index="74" stop-index="85"
text="GROUPING(f1)" function-name="GROUPING(f1)" />
+ </parameter>
+ </function>
+ </expr>
+ </expression-item>
+ </order-by>
+ </select>
+
<select sql-case-id="select_with_exist_in">
<projections start-index="7" stop-index="93">
<expression-projection text="+0
IN(0b111111111111111111111111111111111111111111111111111,rpad(1.0,2048,1),32767.1)"
start-index="7" stop-index="93">
@@ -83,7 +107,7 @@
</expression-projection>
</projections>
</select>
-
+
<select sql-case-id="select_constant_without_table" >
<projections start-index="7" stop-index="12">
<expression-projection text="1" alias="a" start-index="7"
stop-index="12">
@@ -4161,7 +4185,7 @@
</right>
</binary-operation-expression>
</right>
- </binary-operation-expression>
+ </binary-operation-expression>
</left>
<operator>OR</operator>
<right>
@@ -4284,7 +4308,7 @@
</simple-table>
</from>
<projections start-index="7" stop-index="14">
- <column-projection name="order_id" start-index="7" stop-index="14"
/>
+ <column-projection name="order_id" start-index="7" stop-index="14"
/>
</projections>
<where start-index="36" stop-index="69">
<expr>
@@ -4381,12 +4405,12 @@
<column-projection name="USER_NO" start-index="7" stop-index="15">
<owner name="T" start-index="7" stop-index="7" />
</column-projection>>
- </projections>
+ </projections>
</select>
<select sql-case-id="select_with_character_charset">
<projections start-index="7" stop-index="24">
- <!-- TODO StringLiteralValue should consider about _binary/_utf8mb4-->
+ <!-- TODO StringLiteralValue should consider about
_binary/_utf8mb4-->
<expression-projection text="binary'abc" alias="a" start-index="7"
stop-index="24" />
</projections>
</select>
diff --git a/test/it/parser/src/main/resources/sql/supported/dml/select.xml
b/test/it/parser/src/main/resources/sql/supported/dml/select.xml
index ab5e7ed3415..5033668e4e7 100644
--- a/test/it/parser/src/main/resources/sql/supported/dml/select.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dml/select.xml
@@ -18,6 +18,7 @@
<sql-cases>
<sql-case id="select_with_hex_function" value="SELECT HEX(_binary 0x0003
<< (_binary 0x38 | 0x38))" db-types="MySQL" />
+ <sql-case id="select_distinct_with_grouping_function" value="SELECT
DISTINCT f1 FROM t1 GROUP BY f1 WITH ROLLUP ORDER BY f1,
ANY_VALUE(GROUPING(f1))" db-types="MySQL" />
<sql-case id="select_with_exist_in" value="SELECT (+0
IN(0b111111111111111111111111111111111111111111111111111,rpad(1.0,2048,1),32767.1))"
db-types="MySQL" />
<sql-case id="select_constant_without_table" value="SELECT 1 as a"
db-types="MySQL, PostgreSQL,openGauss, SQLServer" />
<sql-case id="select_with_operator_ilike" value="SELECT id from t_order
where name !~ '^pg_toast'" db-types="PostgreSQL,openGauss" />