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 c6f1e284c7e Enhance the support for Oracle SQL parsing (#30526)
c6f1e284c7e is described below
commit c6f1e284c7e17028acfecd692ab15b4f6d221ecc
Author: zhuruixuan <[email protected]>
AuthorDate: Mon Mar 18 18:14:17 2024 +0800
Enhance the support for Oracle SQL parsing (#30526)
* Change1 DDLSTATEMENT
* Change1 BASERULE
* Change1 Supported Sql
* Change1 Case
* Chnage1 Keyword
* Change2 DDLStatement
* Chnage3 DDLStatement
* Change2 Baserule
* Change3 BaseRule
* Change4 BaseRule
* Change4 DDLStatement
* Change2 Keyword
* Change5 DDLStatement
* Change6 DDL
* Change7 DDL
---
.../src/main/antlr4/imports/oracle/BaseRule.g4 | 16 ++++++++++++++++
.../src/main/antlr4/imports/oracle/DDLStatement.g4 | 2 +-
.../oracle/src/main/antlr4/imports/oracle/Keyword.g4 | 20 ++++++++++++++++++++
.../src/main/resources/case/ddl/create-table.xml | 13 +++++++++++++
.../resources/sql/supported/ddl/create-table.xml | 1 +
5 files changed, 51 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 bb039133eb5..b02a9dc8681 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
@@ -2164,3 +2164,19 @@ dbUserProxy
dbUserProxyClauses
: (WITH ((ROLE (ALL EXCEPT)? roleName (COMMA_ roleName)*) | NO ROLES))?
(AUTHENTICATION REQUIRED | AUTHENTICATED USING PASSWORD)?
;
+
+delimSpec
+ : terminatedBySpec? optionallyEnclosedBySpec? lrtrimSpec?
+ ;
+
+terminatedBySpec
+ : TERMINATED BY (STRING_ | WHITESPACE)
+ ;
+
+optionallyEnclosedBySpec
+ : OPTIONALLY? ENCLOSED BY STRING_ AND STRING_
+ ;
+
+lrtrimSpec
+ : LRTRIM
+ ;
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 6ccf832b716..c1628661419 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
@@ -1030,7 +1030,7 @@ externalTableClause
;
externalTableDataProps
- : (DEFAULT DIRECTORY directoryName)? (ACCESS PARAMETERS
((opaqueFormatSpec) | USING CLOB subquery))? (LOCATION LP_ (directoryName
COLON_)? locationSpecifier (COMMA_ (directoryName COLON_)? locationSpecifier)+
RP_)?
+ : (DEFAULT DIRECTORY directoryName)? (ACCESS PARAMETERS ((opaqueFormatSpec
delimSpec)? | USING CLOB subquery))? (LOCATION LP_ (directoryName |
(directoryName COLON_)? locationSpecifier (COMMA_ (directoryName COLON_)?
locationSpecifier)+) RP_)?
;
mappingTableClause
diff --git
a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/Keyword.g4
b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/Keyword.g4
index 1d6593a7aea..1fe037802fb 100644
--- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/Keyword.g4
+++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/Keyword.g4
@@ -927,3 +927,23 @@ CONDITION
EVALUATE
: E V A L U A T E
;
+
+TERMINATED
+ : T E R M I N A T E D
+ ;
+
+WHITESPACE
+ : W H I T E S P A C E
+ ;
+
+OPTIONALLY
+ :O P T I O N A L L Y
+ ;
+
+ENCLOSED
+ : E N C L O S E D
+ ;
+
+LRTRIM
+ :L R T R I M
+ ;
diff --git a/test/it/parser/src/main/resources/case/ddl/create-table.xml
b/test/it/parser/src/main/resources/case/ddl/create-table.xml
index 007b732482a..9141abe3620 100644
--- a/test/it/parser/src/main/resources/case/ddl/create-table.xml
+++ b/test/it/parser/src/main/resources/case/ddl/create-table.xml
@@ -2391,4 +2391,17 @@
</column-definition>
<constraint-definition constraint-name="EC_BOUGHT" start-index="41"
stop-index="113"/>
</create-table>
+
+ <create-table sql-case-id="create_table_with_enclosed" >
+ <table name="emp_load" start-index="13" stop-index="20" />
+ <column-definition type="CHAR" start-index="22" stop-index="40">
+ <column name="first_name" start-index="22" stop-index="31"/>
+ </column-definition>
+ <column-definition type="CHAR" start-index="43" stop-index="60">
+ <column name="last_name" start-index="43" stop-index="51"/>
+ </column-definition>
+ <column-definition type="CHAR" start-index="63" stop-index="83">
+ <column name="year_of_birth" start-index="63" stop-index="75"/>
+ </column-definition>
+ </create-table>
</sql-parser-test-cases>
diff --git
a/test/it/parser/src/main/resources/sql/supported/ddl/create-table.xml
b/test/it/parser/src/main/resources/sql/supported/ddl/create-table.xml
index a8653bbcfd5..f0acfa5af44 100644
--- a/test/it/parser/src/main/resources/sql/supported/ddl/create-table.xml
+++ b/test/it/parser/src/main/resources/sql/supported/ddl/create-table.xml
@@ -323,4 +323,5 @@
<sql-case id="create_table_with_as_sub_query" value="CREATE TABLE
employees_temp AS SELECT * FROM EMPLOYEES;" db-types="Oracle"/>
<sql-case id="create_table_parallel_with_as_sub_query" value="CREATE TABLE
hr.admin_emp_dept PARALLEL COMPRESS AS SELECT * FROM hr.employees WHERE
department_id = 10;" db-types="Oracle"/>
<sql-case id="create_table_with_edge_constraint" value="CREATE TABLE
bought ( PurchaseCount INT ,CONSTRAINT EC_BOUGHT CONNECTION (Customer TO
Product) ON DELETE NO ACTION );" db-types="SQLServer"/>
+ <sql-case id="create_table_with_enclosed" value="CREATE TABLE
emp_load(first_name CHAR(15), last_name CHAR(20), year_of_birth CHAR(4))
ORGANIZATION EXTERNAL (TYPE ORACLE_LOADER DEFAULT DIRECTORY ext_tab_dir ACCESS
PARAMETERS FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '(' and ')'LRTRIM
LOCATION (info.dat));" db-types="Oracle"/>
</sql-cases>