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 b5b27736e2e Fix oracle TO_DATE function parsing (#28284)
b5b27736e2e is described below

commit b5b27736e2e78c9e975bf101f3609c00cfc1d4a1
Author: ZhangCheng <[email protected]>
AuthorDate: Mon Aug 28 16:54:30 2023 +0800

    Fix oracle TO_DATE function parsing (#28284)
    
    * Fix oracle TO_DATE function parsing
    
    * Fix oracle TO_DATE function parsing
---
 .../oracle/visitor/statement/OracleStatementVisitor.java  | 11 ++++++++++-
 test/it/parser/src/main/resources/case/dml/select.xml     | 15 +++++++++++++++
 .../src/main/resources/sql/supported/dml/select.xml       |  1 +
 3 files changed, 26 insertions(+), 1 deletion(-)

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 4cc080ef8cf..20655f76bc9 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
@@ -876,7 +876,11 @@ public abstract class OracleStatementVisitor extends 
OracleStatementBaseVisitor<
         if (null != ctx.cursorFunction()) {
             return visit(ctx.cursorFunction());
         }
-        throw new IllegalStateException("SpecialFunctionContext must have 
castFunction, charFunction, extractFunction, formatFunction, 
firstOrLastValueFunction, trimFunction or featureFunction.");
+        if (null != ctx.toDateFunction()) {
+            return visit(ctx.toDateFunction());
+        }
+        throw new IllegalStateException(
+                "SpecialFunctionContext must have castFunction, charFunction, 
extractFunction, formatFunction, firstOrLastValueFunction, trimFunction, 
toDateFunction or featureFunction.");
     }
     
     @Override
@@ -887,6 +891,11 @@ public abstract class OracleStatementVisitor extends 
OracleStatementBaseVisitor<
         return result;
     }
     
+    @Override
+    public ASTNode visitToDateFunction(final 
OracleStatementParser.ToDateFunctionContext ctx) {
+        return new FunctionSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(), ctx.TO_DATE().getText(), getOriginalText(ctx));
+    }
+    
     @Override
     public final ASTNode visitTranslateFunction(final 
OracleStatementParser.TranslateFunctionContext ctx) {
         FunctionSegment result = new 
FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), 
ctx.TRANSLATE().getText(), getOriginalText(ctx));
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 d1ecc60b23f..d58119ed63f 100644
--- a/test/it/parser/src/main/resources/case/dml/select.xml
+++ b/test/it/parser/src/main/resources/case/dml/select.xml
@@ -6825,4 +6825,19 @@
             </expr>
         </having>
     </select>
+    <select sql-case-id="select_with_to_date_function">
+        <projections start-index="7" stop-index="133" literal-start-index="7" 
literal-stop-index="133">
+            <expression-projection text="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.')" start-index="7" stop-index="133" literal-start-index="7" 
literal-stop-index="133">
+                <literalText>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.')</literalText>
+                <expr>
+                    <function function-name="TO_DATE" text="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.')" start-index="7" stop-index="133" 
literal-start-index="7" literal-stop-index="133">
+                        <literalText>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.')</literalText>
+                    </function>
+                </expr>
+            </expression-projection>
+        </projections>
+        <from>
+            <simple-table name="DUAL" start-index="140" stop-index="143" 
literal-start-index="140" literal-stop-index="143" />
+        </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 406b5556367..237a7e14193 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
@@ -207,4 +207,5 @@
     <sql-case id="select_with_nested_object" value="SELECT 
o.item.line_item_id, o.item.quantity FROM short_orders o;" db-types="Oracle" />
     <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-cases>

Reply via email to