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

chengzhang 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 cba8764b656 Support MySQL SELECT MAX(ALL expr) statement parse (#34639)
cba8764b656 is described below

commit cba8764b6560c8f33ba2cd2aa1f1c2c9c094219f
Author: Zhengqiang Duan <duanzhengqi...@apache.org>
AuthorDate: Wed Feb 12 18:18:13 2025 +0800

    Support MySQL SELECT MAX(ALL expr) statement parse (#34639)
---
 RELEASE-NOTES.md                                   |  1 +
 .../src/main/antlr4/imports/mysql/BaseRule.g4      |  6 +++++-
 .../main/resources/case/dml/select-aggregate.xml   |  9 +++++++++
 .../resources/case/dml/select-special-function.xml | 22 ++++++++++++++++++++++
 .../parser/src/main/resources/case/dml/select.xml  |  8 ++++++++
 .../sql/supported/dml/select-aggregate.xml         |  5 ++---
 .../sql/supported/dml/select-special-function.xml  |  1 +
 .../main/resources/sql/supported/dml/select.xml    |  1 +
 8 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index aa4023f5cdc..4eedfc17986 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -12,6 +12,7 @@
 1. SQL Binder: Support column definition for the WITH clause and 
ExternalTableBinderContext in 
CommonTableExpressionBinder.[#34384](https://github.com/apache/shardingsphere/pull/34384)
 1. SQL Binder: Support case when then else segment bind - 
[#34600](https://github.com/apache/shardingsphere/pull/34600)
 1. SQL Parser: Support MySQL SELECT CAST AS YEAR statement parse - 
[#34638](https://github.com/apache/shardingsphere/pull/34638)
+1. SQL Parser: Support MySQL SELECT MAX(ALL expr) statement parse - 
[#34639](https://github.com/apache/shardingsphere/pull/34639)
 
 ### Bug Fixes
 
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 ede993fc405..f5536f8514c 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
@@ -995,7 +995,7 @@ aggregationExpression
     ;
 
 aggregationFunction
-    : aggregationFunctionName LP_ distinct? aggregationExpression? 
collateClause? separatorName? RP_ overClause?
+    : aggregationFunctionName LP_ (distinct | all)? aggregationExpression? 
collateClause? separatorName? RP_ overClause?
     ;
 
 jsonFunction
@@ -1043,6 +1043,10 @@ distinct
     : DISTINCT
     ;
 
+all
+    : ALL
+    ;
+
 overClause
     : OVER (windowSpecification | identifier)
     ;
diff --git a/test/it/parser/src/main/resources/case/dml/select-aggregate.xml 
b/test/it/parser/src/main/resources/case/dml/select-aggregate.xml
index 08dd5ab8685..0a02b5b8722 100644
--- a/test/it/parser/src/main/resources/case/dml/select-aggregate.xml
+++ b/test/it/parser/src/main/resources/case/dml/select-aggregate.xml
@@ -120,6 +120,15 @@
         </projections>
     </select>
 
+    <select sql-case-id="select_max_with_all">
+        <projections start-index="7" stop-index="37">
+            <aggregation-projection type="MAX" expression="MAX(ALL user_id)" 
alias="max_user_id" start-index="7" stop-index="22" />
+        </projections>
+        <from>
+            <simple-table name="t_order" start-index="44" stop-index="50" />
+        </from>
+    </select>
+
     <select sql-case-id="select_min">
         <from>
             <simple-table name="t_order" start-index="40" stop-index="46" />
diff --git 
a/test/it/parser/src/main/resources/case/dml/select-special-function.xml 
b/test/it/parser/src/main/resources/case/dml/select-special-function.xml
index 6cecd28359e..2929afa1e1a 100644
--- a/test/it/parser/src/main/resources/case/dml/select-special-function.xml
+++ b/test/it/parser/src/main/resources/case/dml/select-special-function.xml
@@ -4049,6 +4049,28 @@
         </from>
     </select>
 
+    <select sql-case-id="select_json_table_with_path">
+        <projections start-index="7" stop-index="7">
+            <shorthand-projection start-index="7" stop-index="7"/>
+        </projections>
+        <from start-index="14" stop-index="71">
+            <function-table start-index="14" stop-index="71" table-alias="t">
+                <table-function function-name="JSON_TABLE" 
text="JSON_TABLE('[]', '$[*]' COLUMNS (p NCHAR PATH '$.a'))">
+                    <parameter>
+                        <literal-expression value="[]" start-index="25" 
stop-index="28" />
+                    </parameter>
+                    <parameter>
+                        <literal-expression value="$[*]" start-index="31" 
stop-index="35" />
+                    </parameter>
+                    <parameter>
+                        <!-- TODO parse json table columns to new segment -->
+                        <literal-expression value="COLUMNS (p NCHAR PATH 
'$.a')" start-index="38" stop-index="65" />
+                    </parameter>
+                </table-function>
+            </function-table>
+        </from>
+    </select>
+
     <select sql-case-id="select_json_type">
         <projections start-index="7" stop-index="26">
             <expression-projection start-index="7" stop-index="26" 
text="JSON_TYPE('[1,2,3]')">
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 9496a23d5d0..3613e3f701e 100644
--- a/test/it/parser/src/main/resources/case/dml/select.xml
+++ b/test/it/parser/src/main/resources/case/dml/select.xml
@@ -10010,4 +10010,12 @@
             </expr>
         </where>
     </select>
+
+    <select sql-case-id="select_with_multi_literals">
+        <projections start-index="7" stop-index="17">
+            <expression-projection text="xxx" start-index="7" stop-index="17">
+                <literal-expression start-index="7" stop-index="17" 
value="xxx" />
+            </expression-projection>
+        </projections>
+    </select>
 </sql-parser-test-cases>
diff --git 
a/test/it/parser/src/main/resources/sql/supported/dml/select-aggregate.xml 
b/test/it/parser/src/main/resources/sql/supported/dml/select-aggregate.xml
index 0cae6e4c9af..cf350826296 100644
--- a/test/it/parser/src/main/resources/sql/supported/dml/select-aggregate.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dml/select-aggregate.xml
@@ -23,6 +23,7 @@
     <sql-case id="select_count_with_sub" value="SELECT COUNT(*) AS 
orders_count FROM t_order WHERE order_id > 1-1" />
     <sql-case id="select_count_with_sub_with_whitespace" value="SELECT 
COUNT(*) AS orders_count FROM t_order WHERE order_id > 1 - 1" />
     <sql-case id="select_max" value="SELECT MAX(user_id) AS max_user_id FROM 
t_order" />
+    <sql-case id="select_max_with_all" value="SELECT MAX(ALL user_id) AS 
max_user_id FROM t_order" db-types="MySQL" />
     <sql-case id="select_min" value="SELECT MIN(user_id) AS min_user_id FROM 
t_order" />
     <sql-case id="select_avg" value="SELECT AVG(user_id) AS user_id_avg FROM 
t_order" />
     <sql-case id="select_count_with_binding_tables_without_join" value="SELECT 
COUNT(*) AS items_count FROM t_order o, t_order_item i WHERE o.user_id = 
i.user_id AND o.order_id = i.order_id AND o.user_id IN (?, ?) AND o.order_id 
BETWEEN ? AND ?" />
@@ -35,9 +36,7 @@
     <sql-case id="select_bit_and" value="SELECT BIT_AND(1)" db-types="MySQL" />
     <sql-case id="select_bit_or" value="SELECT BIT_OR(1)" db-types="MySQL" />
     <sql-case id="select_bit_xor" value="SELECT BIT_XOR(user_id) FROM t_order" 
db-types="MySQL" />
-    <sql-case id="select_approx_count"
-              value="select owner, approx_count(*) , approx_rank(partition by 
owner order by approx_count(*) desc) from t group by owner having 
approx_rank(partition by owner order by approx_count(*) desc) &lt;= 1 order by 
1"
-              db-types="Oracle"/>
+    <sql-case id="select_approx_count" value="select owner, approx_count(*) , 
approx_rank(partition by owner order by approx_count(*) desc) from t group by 
owner having approx_rank(partition by owner order by approx_count(*) desc) 
&lt;= 1 order by 1" db-types="Oracle"/>
     <sql-case id="select_group_concat" value="SELECT GROUP_CONCAT(user_id) AS 
user_id_group_concat FROM t_order" db-types="MySQL,Doris,openGauss"/>
     <sql-case id="select_group_concat_with_distinct_with_separator" 
value="SELECT GROUP_CONCAT(distinct user_id SEPARATOR ' ') AS 
user_id_group_concat FROM t_order" db-types="MySQL,Doris,openGauss"/>
 </sql-cases>
diff --git 
a/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml
 
b/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml
index e0e2515e7bd..d8349168daa 100644
--- 
a/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml
+++ 
b/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml
@@ -239,6 +239,7 @@
     <sql-case id="select_json_storage_free" value="SELECT 
JSON_STORAGE_FREE(json_col) FROM t" db-types="MySQL" />
     <sql-case id="select_json_storage_size" value="SELECT 
JSON_STORAGE_SIZE(json_col) FROM t" db-types="MySQL" />
     <sql-case id="select_json_table" value="SELECT * FROM 
JSON_TABLE('[{&quot;name&quot;: 2}]','$[*]' COLUMNS( name INT PATH '$.name' 
error on empty)) as t" db-types="MySQL" />
+    <sql-case id="select_json_table_with_path" value="SELECT * FROM 
JSON_TABLE('[]', '$[*]' COLUMNS (p NCHAR PATH '$.a')) AS t" db-types="MySQL" />
     <sql-case id="select_json_type" value="SELECT JSON_TYPE('[1,2,3]')" 
db-types="MySQL" />
     <sql-case id="select_json_unquote" value="SELECT 
JSON_UNQUOTE('&quot;abc&quot;')" db-types="MySQL" />
     <sql-case id="select_json_valid" value="SELECT JSON_VALID('{&quot;a&quot;: 
1}')" db-types="MySQL" />
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 b945cf62049..8b60c70215f 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
@@ -312,4 +312,5 @@
     <sql-case id="select_with_not_operator_boolean" value="SELECT NOT TRUE, 
NOT FALSE" db-types="MySQL" />
     <sql-case id="select_with_zone_keyword" value="SELECT order_id, zone FROM 
t_order" db-types="MySQL" />
     <sql-case id="select_with_reserved_word_range_and_table_owner" 
value="SELECT * FROM t_order o WHERE o.range = 1" db-types="MySQL"/>
+    <sql-case id="select_with_multi_literals" value="SELECT 'x' 'x' 'x'" 
db-types="MySQL"/>
 </sql-cases>

Reply via email to