You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2023/08/26 07:56:47 UTC

[shardingsphere] branch master updated: Add oracle TO_DATE function parse (#28261)

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

duanzhengqiang 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 0e461667a8d Add oracle TO_DATE function parse (#28261)
0e461667a8d is described below

commit 0e461667a8d9a9de3d2a72549e5f63415ac3d074
Author: niu niu <zi...@aliyun.com>
AuthorDate: Sat Aug 26 15:56:40 2023 +0800

    Add oracle TO_DATE function parse (#28261)
    
    * Format addTablePartition definition
    
    * Add oracle TO_DATE function parse
    
    * Add oracle TO_DATE function parse
---
 .../src/main/antlr4/imports/oracle/BaseRule.g4     |  6 +++++-
 .../src/main/antlr4/imports/oracle/DDLStatement.g4 | 12 +++++------
 .../main/antlr4/imports/oracle/OracleKeyword.g4    |  4 ++++
 .../src/main/resources/case/ddl/alter-table.xml    | 25 ++++++++++++++++++++++
 .../resources/sql/supported/ddl/alter-table.xml    |  5 +++++
 5 files changed, 44 insertions(+), 8 deletions(-)

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 7181023448c..456ed5874bb 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
@@ -775,7 +775,11 @@ leadLagInfo
 
 specialFunction
     : castFunction | charFunction | extractFunction | formatFunction | firstOrLastValueFunction | trimFunction | featureFunction
-    | setFunction | translateFunction | cursorFunction
+    | setFunction | translateFunction | cursorFunction | toDateFunction
+    ;
+
+toDateFunction
+    : TO_DATE LP_ char=STRING_ (DEFAULT returnValue=STRING_ ON CONVERSION ERROR)? (COMMA_ fmt=STRING_ (COMMA_ STRING_)?)? RP_
     ;
 
 cursorFunction
diff --git a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4
index 8b6e72a5fb3..65236da333a 100644
--- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4
+++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4
@@ -923,7 +923,7 @@ rangePartitions
     ;
 
 rangeValuesClause
-    : VALUES LESS THAN LP_? (numberLiterals | MAXVALUE) (COMMA_ (numberLiterals | MAXVALUE))* RP_?
+    : VALUES LESS THAN LP_? (literals | MAXVALUE | toDateFunction) (COMMA_ (literals | MAXVALUE | toDateFunction))* RP_?
     ;
 
 tablePartitionDescription
@@ -1407,12 +1407,10 @@ coalesceTablePartition
     ;
 
 addTablePartition
-    : ADD ((PARTITION partitionName? addRangePartitionClause (COMMA_ PARTITION partitionName? addRangePartitionClause)*)
-        |  (PARTITION partitionName? addListPartitionClause (COMMA_ PARTITION partitionName? addListPartitionClause)*)
-        |  (PARTITION partitionName? addSystemPartitionClause (COMMA_ PARTITION partitionName? addSystemPartitionClause)*)
-        (BEFORE (partitionName | NUMBER_))?
-        |  (PARTITION partitionName? addHashPartitionClause)
-        ) dependentTablesClause?
+    : ADD (PARTITION partitionName? addRangePartitionClause (COMMA_ PARTITION partitionName? addRangePartitionClause)* 
+    | PARTITION partitionName? addListPartitionClause (COMMA_ PARTITION partitionName? addListPartitionClause)* 
+    | PARTITION partitionName? addSystemPartitionClause (COMMA_ PARTITION partitionName? addSystemPartitionClause)* (BEFORE? (partitionName | NUMBER_)?) 
+    | PARTITION partitionName? addHashPartitionClause) dependentTablesClause?
     ;
 
 addRangePartitionClause
diff --git a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4 b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4
index afab9bfc90b..265f7060e62 100644
--- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4
+++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4
@@ -59,6 +59,10 @@ CHECK
     : C H E C K
     ;
 
+CONVERSION
+    : C O N V E R S I O N
+    ;
+
 GENERATED
     : G E N E R A T E D
     ;
diff --git a/test/it/parser/src/main/resources/case/ddl/alter-table.xml b/test/it/parser/src/main/resources/case/ddl/alter-table.xml
index 0770df10f77..b2be68a1b7a 100644
--- a/test/it/parser/src/main/resources/case/ddl/alter-table.xml
+++ b/test/it/parser/src/main/resources/case/ddl/alter-table.xml
@@ -143,6 +143,15 @@
         </modify-column>
     </alter-table>
     
+    <alter-table sql-case-id="alter_table_modify12">
+        <table name="product_information" start-index="12" stop-index="30" />
+        <modify-column>
+            <column-definition start-index="40" stop-index="59">
+                <column name="min_price" />
+            </column-definition>
+        </modify-column>
+    </alter-table>
+    
     <alter-table sql-case-id="alter_table_add_constraint">
         <table name="employees" start-index="12" stop-index="20" />
         <add-constraint constraint-name="emp_emp_id_pk" start-index="27" stop-index="76">
@@ -1568,4 +1577,20 @@
     <alter-table sql-case-id="alter_table_modify_subpartition_rebuild_unusable_local_indexes">
         <table name="emp" start-index="12" stop-index="14" />
     </alter-table>
+    
+    <alter-table sql-case-id="alter_table_modify_subpartition_add_values">
+        <table name="quarterly_regional_sales" start-index="12" stop-index="35" />
+    </alter-table>
+    
+    <alter-table sql-case-id="alter_table_add_partition_values_less_than1">
+        <table name="quarterly_regional_sales" start-index="12" stop-index="35" />
+    </alter-table>
+
+    <alter-table sql-case-id="alter_table_add_partition_values_less_than2">
+        <table name="sales" start-index="12" stop-index="16" />
+    </alter-table>
+    
+    <alter-table sql-case-id="alter_table_modify_subpartition_drop_values">
+        <table name="quarterly_regional_sales" start-index="12" stop-index="35" />
+    </alter-table>
 </sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/alter-table.xml b/test/it/parser/src/main/resources/sql/supported/ddl/alter-table.xml
index 99a84e9241c..d2aadecf740 100644
--- a/test/it/parser/src/main/resources/sql/supported/ddl/alter-table.xml
+++ b/test/it/parser/src/main/resources/sql/supported/ddl/alter-table.xml
@@ -32,6 +32,7 @@
     <sql-case id="alter_table_modify9" value="ALTER TABLE sales MODIFY CONSTRAINT time_view_fk RELY" db-types="Oracle" />
     <sql-case id="alter_table_modify10" value="ALTER TABLE locations_demo MODIFY (country_id CONSTRAINT country_nn NOT NULL)" db-types="Oracle" />
     <sql-case id="alter_table_modify11" value="ALTER TABLE product_information MODIFY (min_price DEFAULT NULL)" db-types="Oracle" />
+    <sql-case id="alter_table_modify12" value="ALTER TABLE product_information MODIFY (min_price DEFAULT 10)" db-types="Oracle" />
     <sql-case id="alter_table_add_constraint" value="ALTER TABLE employees ADD (CONSTRAINT emp_emp_id_pk PRIMARY KEY (employee_id), CONSTRAINT emp_dept_fk FOREIGN KEY (department_id) REFERENCES departments, CONSTRAINT emp_job_fk FOREIGN KEY (job_id) REFERENCES jobs (job_id), CONSTRAINT emp_manager_fk FOREIGN KEY (manager_id) REFERENCES employees)" db-types="Oracle" />
     <sql-case id="alter_table_no_flashback_archive" value="ALTER TABLE employee NO FLASHBACK ARCHIVE" db-types="Oracle" />
     <sql-case id="alter_table_move_tablespace_overflow_tablespace" value="ALTER TABLE admin_docindex MOVE TABLESPACE admin_tbs2 OVERFLOW TABLESPACE admin_tbs3" db-types="Oracle" />
@@ -204,4 +205,8 @@
     <sql-case id="alter_table_move_tablespace1" value="ALTER TABLE people_tab MOVE TABLESPACE system" db-types="Oracle" />
     <sql-case id="alter_table_move_tablespace2" value="ALTER TABLE people_column_nt MOVE TABLESPACE example" db-types="Oracle" />
     <sql-case id="alter_table_modify_subpartition_rebuild_unusable_local_indexes" value="ALTER TABLE emp MODIFY SUBPARTITION p3_s1 REBUILD UNUSABLE LOCAL INDEXES" db-types="Oracle" />
+    <sql-case id="alter_table_modify_subpartition_add_values" value="ALTER TABLE quarterly_regional_sales MODIFY SUBPARTITION q1_1999_southeast ADD VALUES ('KS')" db-types="Oracle" />
+    <sql-case id="alter_table_add_partition_values_less_than1" value="ALTER TABLE quarterly_regional_sales ADD PARTITION q1_2000 VALUES LESS THAN (TO_DATE('1-APR-2000','DD-MON-YYYY')) STORAGE (INITIAL 20K NEXT 20K) TABLESPACE ts3 NOLOGGING(SUBPARTITION q1_2000_northwest VALUES ('OR', 'WA'), SUBPARTITION q1_2000_southwest VALUES ('AZ', 'UT', 'NM'), SUBPARTITION q1_2000_northeast VALUES ('NY', 'VM', 'NJ'), SUBPARTITION q1_2000_southeast VALUES ('FL', 'GA'), SUBPARTITION q1_2000_northcentra [...]
+    <sql-case id="alter_table_add_partition_values_less_than2" value="ALTER TABLE sales ADD PARTITION jan99 VALUES LESS THAN ('01-FEB-1999') TABLESPACE tsx" db-types="Oracle" />
+    <sql-case id="alter_table_modify_subpartition_drop_values" value="ALTER TABLE quarterly_regional_sales MODIFY SUBPARTITION q1_1999_southeast DROP VALUES ('KS')" db-types="Oracle" />
 </sql-cases>