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

tuichenchuxin 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 d91de3a5586 Support extracting column information from oracle 
projections (#28295)
d91de3a5586 is described below

commit d91de3a5586e0a7cb60321619e2ddb62c041524a
Author: ZhangCheng <[email protected]>
AuthorDate: Tue Aug 29 10:37:00 2023 +0800

    Support extracting column information from oracle projections (#28295)
    
    * Support extracting column information from oracle projections
    
    * Support extracting column information from oracle projections
---
 .../visitor/statement/OracleStatementVisitor.java  | 11 ++++
 .../parser/src/main/resources/case/dml/delete.xml  | 12 +++-
 .../main/resources/case/dml/select-group-by.xml    |  9 ++-
 .../parser/src/main/resources/case/dml/select.xml  | 71 ++++++++++++++++++++++
 .../main/resources/sql/supported/dml/select.xml    |  1 +
 5 files changed, 102 insertions(+), 2 deletions(-)

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 20655f76bc9..5400b5d2e8d 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
@@ -548,6 +548,17 @@ public abstract class OracleStatementVisitor extends 
OracleStatementBaseVisitor<
         if (null != ctx.privateExprOfDb()) {
             return visit(ctx.privateExprOfDb());
         }
+        if (null != ctx.LP_()) {
+            if (1 == ctx.expr().size()) {
+                return visit(ctx.expr(0));
+            } else {
+                ListExpression result = new 
ListExpression(ctx.LP_().getSymbol().getStartIndex(), 
ctx.RP_().getSymbol().getStopIndex());
+                for (ExprContext each : ctx.expr()) {
+                    result.getItems().add((ExpressionSegment) visit(each));
+                }
+                return result;
+            }
+        }
         return new CommonExpressionSegment(startIndex, stopIndex, 
ctx.getText());
     }
     
diff --git a/test/it/parser/src/main/resources/case/dml/delete.xml 
b/test/it/parser/src/main/resources/case/dml/delete.xml
index a4e3e5f8520..a717a5067bf 100644
--- a/test/it/parser/src/main/resources/case/dml/delete.xml
+++ b/test/it/parser/src/main/resources/case/dml/delete.xml
@@ -129,7 +129,17 @@
                 <in-expression start-index="38" stop-index="211">
                     <not>false</not>
                     <left>
-                        <common-expression 
text="(product_id,currency_code,effective_from_date)" start-index="38" 
stop-index="85" />
+                        <list-expression start-index="38" stop-index="85" 
literal-start-index="38" literal-stop-index="85">
+                            <items>
+                                <column name="product_id" start-index="39" 
stop-index="48" literal-start-index="39" literal-stop-index="48" />
+                            </items>
+                            <items>
+                                <column name="currency_code" start-index="51" 
stop-index="63" literal-start-index="51" literal-stop-index="63" />
+                            </items>
+                            <items>
+                                <column name="effective_from_date" 
start-index="66" stop-index="84" literal-start-index="66" 
literal-stop-index="84" />
+                            </items>
+                        </list-expression>
                     </left>
                     <right>
                         <subquery start-index="90" stop-index="211">
diff --git a/test/it/parser/src/main/resources/case/dml/select-group-by.xml 
b/test/it/parser/src/main/resources/case/dml/select-group-by.xml
index e3cb0819f1f..688a1ef93e6 100644
--- a/test/it/parser/src/main/resources/case/dml/select-group-by.xml
+++ b/test/it/parser/src/main/resources/case/dml/select-group-by.xml
@@ -583,7 +583,14 @@
                 <in-expression start-index="90" stop-index="219">
                     <not>false</not>
                     <left>
-                        <common-expression text="(department_id,manager_id)" 
start-index="90" stop-index="116" />
+                        <list-expression start-index="90" stop-index="116" 
literal-start-index="90" literal-stop-index="116">
+                            <items>
+                                <column name="department_id" start-index="91" 
stop-index="103" literal-start-index="91" literal-stop-index="103" />
+                            </items>
+                            <items>
+                                <column name="manager_id" start-index="106" 
stop-index="115" literal-start-index="106" literal-stop-index="115" />
+                            </items>
+                        </list-expression>
                     </left>
                     <right>
                         <subquery start-index="121" stop-index="219">
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 d58119ed63f..93ce5e385ee 100644
--- a/test/it/parser/src/main/resources/case/dml/select.xml
+++ b/test/it/parser/src/main/resources/case/dml/select.xml
@@ -6840,4 +6840,75 @@
             <simple-table name="DUAL" start-index="140" stop-index="143" 
literal-start-index="140" literal-stop-index="143" />
         </from>
     </select>
+    <select sql-case-id="select_with_expressions_in_projection">
+        <projections start-index="7" stop-index="81" literal-start-index="7" 
literal-stop-index="81">
+            <column-projection name="empid" start-index="75" stop-index="81" 
literal-start-index="75" literal-stop-index="81">
+                <owner name="a" start-index="75" stop-index="75" 
literal-start-index="75" literal-stop-index="75" />
+            </column-projection>
+            <expression-projection text="a.enddate - term + term2 + 1) / 
(last_day(term) - term + 1" alias="cnt" start-index="8" stop-index="72" 
literal-start-index="8" literal-stop-index="72">
+                <literalText>a.enddate - term + term2 + 1) / (last_day(term) - 
term + 1</literalText>
+                <expr>
+                    <binary-operation-expression start-index="8" 
stop-index="67" literal-start-index="8" literal-stop-index="67">
+                        <left>
+                            <binary-operation-expression start-index="9" 
stop-index="36" literal-start-index="9" literal-stop-index="36">
+                                <left>
+                                    <column name="enddate" start-index="9" 
stop-index="17" literal-start-index="9" literal-stop-index="17">
+                                        <owner name="a" start-index="9" 
stop-index="9" literal-start-index="9" literal-stop-index="9" />
+                                    </column>
+                                </left>
+                                <operator>-</operator>
+                                <right>
+                                    <binary-operation-expression 
start-index="21" stop-index="36" literal-start-index="21" 
literal-stop-index="36">
+                                        <left>
+                                            <binary-operation-expression 
start-index="21" stop-index="32" literal-start-index="21" 
literal-stop-index="32">
+                                                <left>
+                                                    <column name="term" 
start-index="21" stop-index="24" literal-start-index="21" 
literal-stop-index="24" />
+                                                </left>
+                                                <operator>+</operator>
+                                                <right>
+                                                    <column name="term2" 
start-index="28" stop-index="32" literal-start-index="28" 
literal-stop-index="32" />
+                                                </right>
+                                            </binary-operation-expression>
+                                        </left>
+                                        <operator>+</operator>
+                                        <right>
+                                            <literal-expression value="1" 
start-index="36" stop-index="36" literal-start-index="36" 
literal-stop-index="36" />
+                                        </right>
+                                    </binary-operation-expression>
+                                </right>
+                            </binary-operation-expression>
+                        </left>
+                        <operator>/</operator>
+                        <right>
+                            <binary-operation-expression start-index="42" 
stop-index="66" literal-start-index="42" literal-stop-index="66">
+                                <left>
+                                    <function function-name="last_day" 
text="last_day(term)" start-index="42" stop-index="55" literal-start-index="42" 
literal-stop-index="55">
+                                        <parameter>
+                                            <column name="term" 
start-index="51" stop-index="54" literal-start-index="51" 
literal-stop-index="54" />
+                                        </parameter>
+                                        
<literalText>last_day(term)</literalText>
+                                    </function>
+                                </left>
+                                <operator>-</operator>
+                                <right>
+                                    <binary-operation-expression 
start-index="59" stop-index="66" literal-start-index="59" 
literal-stop-index="66">
+                                        <left>
+                                            <column name="term" 
start-index="59" stop-index="62" literal-start-index="59" 
literal-stop-index="62" />
+                                        </left>
+                                        <operator>+</operator>
+                                        <right>
+                                            <literal-expression value="1" 
start-index="66" stop-index="66" literal-start-index="66" 
literal-stop-index="66" />
+                                        </right>
+                                    </binary-operation-expression>
+                                </right>
+                            </binary-operation-expression>
+                        </right>
+                    </binary-operation-expression>
+                </expr>
+            </expression-projection>
+        </projections>
+        <from>
+            <simple-table alias="aWHERE" name="employee" start-index="88" 
stop-index="102" literal-start-index="88" literal-stop-index="102" />
+        </from>
+    </select>
 </sql-parser-test-cases>
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 237a7e14193..ac5ee474bba 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
@@ -208,4 +208,5 @@
     <sql-case id="select_with_collection_table" value="SELECT VALUE(p) FROM 
warehouses w, TABLE(XMLSEQUENCE(EXTRACT(warehouse_spec, '/Warehouse/*'))) p;" 
db-types="Oracle" />
     <sql-case id="select_with_group_by_and_having" value="select cfg_name from 
bmsql_config group by cfg_name having cfg_name='1';" db-types="openGauss" />
     <sql-case id="select_with_to_date_function" value="SELECT TO_DATE('Febuary 
15, 2016, 11:00 A.M.' DEFAULT 'January 01, 2016 12:00 A.M.' ON CONVERSION 
ERROR, 'Month dd, YYYY, HH:MI A.M.') FROM DUAL;" db-types="Oracle" />
+    <sql-case id="select_with_expressions_in_projection" value="SELECT 
((a.enddate - term + term2 + 1) / (last_day(term) - term + 1)) cnt, a.empid 
FROM employee aWHERE nvl(disabled, 0) = 1  AND enddate BETWEEN term AND 
last_day(term)  AND EXISTS (SELECT 1 FROM post d WHERE a.orgid = d.orgid   AND 
a.postid = d.postid   AND d.title != 'TEST'   AND nvl(d.postid, 0) != 0)" 
db-types="Oracle" />
 </sql-cases>

Reply via email to