You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2022/11/11 06:47:40 UTC

[shardingsphere] branch master updated: Update Oracle DML SLELECT PERCENTILE_DISC statement parse (#22070)

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

jianglongtao 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 3f266392ab8 Update Oracle DML SLELECT PERCENTILE_DISC statement parse (#22070)
3f266392ab8 is described below

commit 3f266392ab8a442e92b2713a858f6ef69f424d6a
Author: Zichao <57...@users.noreply.github.com>
AuthorDate: Fri Nov 11 19:47:32 2022 +1300

    Update Oracle DML SLELECT PERCENTILE_DISC statement parse (#22070)
---
 .../src/main/antlr4/imports/oracle/BaseRule.g4     |  2 +-
 .../src/main/antlr4/imports/oracle/Keyword.g4      |  4 +++
 test/parser/src/main/resources/case/dml/select.xml | 37 ++++++++++++++++++++++
 .../main/resources/sql/supported/dml/select.xml    |  1 +
 4 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/sql-parser/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4 b/sql-parser/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4
index dc450244e3f..cb5c594f4fe 100644
--- a/sql-parser/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4
+++ b/sql-parser/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4
@@ -515,7 +515,7 @@ aggregationFunction
     ;
 
 aggregationFunctionName
-    : MAX | MIN | SUM | COUNT | AVG | GROUPING | LISTAGG | PERCENT_RANK | PERCENTILE_CONT
+    : MAX | MIN | SUM | COUNT | AVG | GROUPING | LISTAGG | PERCENT_RANK | PERCENTILE_CONT | PERCENTILE_DISC
     ;
 
 listaggOverflowClause
diff --git a/sql-parser/dialect/oracle/src/main/antlr4/imports/oracle/Keyword.g4 b/sql-parser/dialect/oracle/src/main/antlr4/imports/oracle/Keyword.g4
index 887f9683a48..d0a9bc80f77 100644
--- a/sql-parser/dialect/oracle/src/main/antlr4/imports/oracle/Keyword.g4
+++ b/sql-parser/dialect/oracle/src/main/antlr4/imports/oracle/Keyword.g4
@@ -583,3 +583,7 @@ ROWTYPE
 PERCENTILE_CONT
     : P E R C E N T I L E UL_ C O N T
     ;
+
+PERCENTILE_DISC
+    : P E R C E N T I L E UL_ D I S C
+    ;
diff --git a/test/parser/src/main/resources/case/dml/select.xml b/test/parser/src/main/resources/case/dml/select.xml
index b741d4b870d..a259f50b70a 100644
--- a/test/parser/src/main/resources/case/dml/select.xml
+++ b/test/parser/src/main/resources/case/dml/select.xml
@@ -4485,4 +4485,41 @@
             <simple-table name="employees" start-index="98" stop-index="106" />
         </from>
     </select>
+
+    <select sql-case-id="select_aggregate_percentile_disc">
+        <projections start-index="7" stop-index="148">
+            <column-projection name="department_id" start-index="7" stop-index="19" />
+            <column-projection name="last_name" start-index="22" stop-index="30" />
+            <column-projection name="salary" start-index="33" stop-index="38" />
+            <expression-projection text="PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY salary DESC) OVER (PARTITION BY department_id)" alias="Percentile_Disc" start-index="41" stop-index="148" />
+        </projections>
+        <from>
+            <simple-table name="employees" start-index="155" stop-index="163" />
+        </from>
+        <where start-index="165" stop-index="195">
+            <expr>
+                <in-expression start-index="171" stop-index="195">
+                    <not>false</not>
+                    <left>
+                        <column name="department_id" start-index="171" stop-index="183"/>
+                    </left>
+                    <right>
+                        <list-expression start-index="188" stop-index="195">
+                            <items>
+                                <literal-expression value="30" start-index="189" stop-index="190" />
+                            </items>
+                            <items>
+                                <literal-expression value="60" start-index="193" stop-index="194" />
+                            </items>
+                        </list-expression>
+                    </right>
+                </in-expression>
+            </expr>
+        </where>
+        <order-by>
+            <column-item name="last_name" start-index="206" stop-index="214" />
+            <column-item name="salary" start-index="217" stop-index="222" />
+            <column-item name="department_id" start-index="225" stop-index="237" />
+        </order-by>
+    </select>
 </sql-parser-test-cases>
diff --git a/test/parser/src/main/resources/sql/supported/dml/select.xml b/test/parser/src/main/resources/sql/supported/dml/select.xml
index 09ae96c16e3..7fa796fb25f 100644
--- a/test/parser/src/main/resources/sql/supported/dml/select.xml
+++ b/test/parser/src/main/resources/sql/supported/dml/select.xml
@@ -137,4 +137,5 @@
     <sql-case id="select_aggregate_percent_rank" value="SELECT PERCENT_RANK(15000, .05) WITHIN GROUP (ORDER BY salary, commission_pct) 'Percent-Rank' FROM employees;" db-types="Oracle" />
     <sql-case id="select_analytic_percent_rank" value="SELECT department_id, last_name, salary, PERCENT_RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS pr FROM employees ORDER BY pr, salary, last_name;" db-types="Oracle" />
     <sql-case id="select_aggregate_percentile_cont" value="SELECT department_id, PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY salary DESC) 'Median cont' FROM employees;" db-types="Oracle" />
+    <sql-case id="select_aggregate_percentile_disc" value="SELECT department_id, last_name, salary, PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY salary DESC) OVER (PARTITION BY department_id) 'Percentile_Disc' FROM employees WHERE department_id in (30, 60) ORDER BY last_name, salary, department_id;" db-types="Oracle" />
 </sql-cases>