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 2023/08/04 03:25:45 UTC

[shardingsphere] branch master updated: [Oracle SQL] Support parsing set function for Oracle SQL (#27895)

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 13dcbf82a8f [Oracle SQL] Support parsing set function for Oracle SQL (#27895)
13dcbf82a8f is described below

commit 13dcbf82a8f5785a59f9d304d3876cc835407edd
Author: Liao Lanyu <14...@qq.com>
AuthorDate: Fri Aug 4 11:25:39 2023 +0800

    [Oracle SQL] Support parsing set function for Oracle SQL (#27895)
    
    * support set function
    
    * support set function test
---
 .../src/main/antlr4/imports/oracle/BaseRule.g4      |  6 +++++-
 .../visitor/statement/OracleStatementVisitor.java   | 10 ++++++++++
 .../resources/case/dml/select-special-function.xml  | 21 +++++++++++++++++++++
 .../sql/supported/dml/select-special-function.xml   |  1 +
 4 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4 b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4
index 098fbabb399..2569e81206a 100644
--- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4
+++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4
@@ -758,7 +758,11 @@ leadLagInfo
     ;
 
 specialFunction
-    : castFunction | charFunction | extractFunction | formatFunction | firstOrLastValueFunction | trimFunction | featureFunction
+    : castFunction | charFunction | extractFunction | formatFunction | firstOrLastValueFunction | trimFunction | featureFunction | setFunction
+    ;
+
+setFunction
+    : SET LP_ expr RP_
     ;
 
 featureFunction
diff --git a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/OracleStatementVisitor.java b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/OracleStatementVisitor.java
index 81d7c0e6c33..caff2b6348d 100644
--- a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/OracleStatementVisitor.java
+++ b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/OracleStatementVisitor.java
@@ -868,9 +868,19 @@ public abstract class OracleStatementVisitor extends OracleStatementBaseVisitor<
         if (null != ctx.featureFunction()) {
             return visit(ctx.featureFunction());
         }
+        if (null != ctx.setFunction()) {
+            return visit(ctx.setFunction());
+        }
         throw new IllegalStateException("SpecialFunctionContext must have castFunction, charFunction, extractFunction, formatFunction, firstOrLastValueFunction, trimFunction or featureFunction.");
     }
     
+    @Override
+    public final ASTNode visitSetFunction(final OracleStatementParser.SetFunctionContext ctx) {
+        FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.SET().getText(), getOriginalText(ctx));
+        result.getParameters().add((ExpressionSegment) visit(ctx.expr()));
+        return result;
+    }
+    
     @Override
     public final ASTNode visitCastFunction(final CastFunctionContext ctx) {
         FunctionSegment result;
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 765f66aafa4..89d44df472d 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
@@ -546,4 +546,25 @@
             <column-item name="xmlagg" order-direction="ASC" start-index="98" stop-index="103"/>
         </order-by>
     </select>
+
+    <select sql-case-id="select_set_function">
+        <projections start-index="7" stop-index="49">
+            <column-projection name="customer_id" start-index="7" stop-index="17" />
+            <expression-projection text="SET(cust_address_ntab)" alias="address" start-index="20" stop-index="49">
+                <expr>
+                    <function function-name="SET" start-index="20" stop-index="41" text="SET(cust_address_ntab)">
+                        <parameter>
+                            <column name="cust_address_ntab" start-index="24" stop-index="40" />
+                        </parameter>
+                    </function>
+                </expr>
+            </expression-projection>
+        </projections>
+        <from>
+            <simple-table name="customers_demo" start-index="56" stop-index="69" />
+        </from>
+        <order-by>
+            <column-item name="customer_id" order-direction="ASC" start-index="80" stop-index="90" literal-start-index="80" literal-stop-index="90" />
+        </order-by>
+    </select>
 </sql-parser-test-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 d9233bfb53c..5f8e8b70518 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
@@ -42,4 +42,5 @@
     <sql-case id="select_extract_function_for_oracle" value="SELECT EXTRACT(YEAR FROM TIMESTAMP '2001-02-16 20:38:40') FROM DUAL" db-types="Oracle" />
     <sql-case id="select_mod_function" value="SELECT MOD(order_id, 1) from t_order" db-types="PostgreSQL,openGauss" />
     <sql-case id="select_sys_xml_agg" value="SELECT SYS_XMLAGG(SYS_XMLGEN(last_name)) XMLAGG FROM employees WHERE last_name LIKE 'R%' ORDER BY xmlagg;" db-types="Oracle" />
+    <sql-case id="select_set_function" value="SELECT customer_id, SET(cust_address_ntab) address FROM customers_demo ORDER BY customer_id;" db-types="Oracle" />
 </sql-cases>