This is an automated email from the ASF dual-hosted git repository.
chengzhang 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 5221b78a2af Optimize Oracle support create table as select. (#28378)
5221b78a2af is described below
commit 5221b78a2afd29c7af55f1595b40f08b1b6e49c8
Author: Cong Hu <[email protected]>
AuthorDate: Thu Sep 7 16:48:12 2023 +0800
Optimize Oracle support create table as select. (#28378)
---
.../src/main/antlr4/imports/oracle/BaseRule.g4 | 10 +--------
.../src/main/antlr4/imports/oracle/DDLStatement.g4 | 24 ++++++++++------------
.../src/main/antlr4/imports/oracle/DMLStatement.g4 | 9 ++------
.../sql/parser/autogen/OracleStatement.g4 | 2 +-
.../src/main/resources/case/ddl/create-table.xml | 4 ++++
.../resources/sql/supported/ddl/create-table.xml | 1 +
6 files changed, 20 insertions(+), 30 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 686c07c74fa..d3f383de364 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
@@ -884,10 +884,6 @@ caseElse
: ELSE expr
;
-subquery
- : matchNone
- ;
-
orderByClause
: ORDER SIBLINGS? BY orderByItem (COMMA_ orderByItem)*
;
@@ -1000,10 +996,6 @@ ignoredIdentifiers
: ignoredIdentifier (COMMA_ ignoredIdentifier)*
;
-matchNone
- : 'Default does not match anything'
- ;
-
hashSubpartitionQuantity
: NUMBER
;
@@ -1699,7 +1691,7 @@ existsCondition
;
inCondition
- : (expr NOT? IN LP_ (expressionList | subquery) RP_)
+ : (expr NOT? IN LP_ (expressionList | subquery) RP_)
| (exprList NOT? IN LP_ ((expressionList (COMMA_ expressionList)*) |
subquery) RP_)
;
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 a6a5c4c9493..765b7925b84 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
@@ -17,7 +17,7 @@
grammar DDLStatement;
-import BaseRule, DCLStatement;
+import BaseRule, DCLStatement, DMLStatement;
createTable
: CREATE createTableSpecification TABLE tableName createSharingClause
createDefinitionClause createMemOptimizeClause createParentClause
@@ -178,7 +178,11 @@ createSharingClause
;
createDefinitionClause
- : createRelationalTableClause | createObjectTableClause |
createXMLTypeTableClause
+ : createRelationalTableClause | createObjectTableClause |
createTableAsSelectClause | createXMLTypeTableClause
+ ;
+
+createTableAsSelectClause
+ : AS selectSubquery
;
createXMLTypeTableClause
@@ -296,7 +300,7 @@ identityOption
;
encryptionSpecification
- : (USING STRING_)? (IDENTIFIED BY STRING_)? (integrityAlgorithm? (NO?
SALT)? | (NO? SALT)? integrityAlgorithm?)
+ : (USING STRING_)? (IDENTIFIED BY STRING_)? (integrityAlgorithm? (NO?
SALT)? | (NO? SALT)? integrityAlgorithm?)
;
inlineConstraint
@@ -2160,7 +2164,7 @@ scopeClause
analyze
: (ANALYZE ((TABLE tableName| INDEX indexName) partitionExtensionClause? |
CLUSTER clusterName))
- (validationClauses | LIST CHAINED ROWS intoClause? | DELETE SYSTEM?
STATISTICS)
+ (validationClauses | LIST CHAINED ROWS intoTableClause? | DELETE SYSTEM?
STATISTICS)
;
partitionExtensionClause
@@ -2170,10 +2174,10 @@ partitionExtensionClause
validationClauses
: VALIDATE REF UPDATE (SET DANGLING TO NULL)?
- | VALIDATE STRUCTURE (CASCADE (FAST | COMPLETE? (OFFLINE | ONLINE)
intoClause?)?)?
+ | VALIDATE STRUCTURE (CASCADE (FAST | COMPLETE? (OFFLINE | ONLINE)
intoTableClause?)?)?
;
-intoClause
+intoTableClause
: INTO tableName
;
@@ -3641,7 +3645,7 @@ pdbUnplugEncrypt
pdbSettingsClauses
: pdbName? pdbSettingClause
- | CONTAINERS containersClause
+ | CONTAINERS (DEFAULT TARGET EQ_ ((LP_ containerName RP_) | NONE) | HOST
EQ_ hostName | PORT EQ_ NUMBER_)
;
pdbSettingClause
@@ -3660,12 +3664,6 @@ pdbSettingClause
| SET CONTAINER_MAP EQ_ mapObject
;
-containersClause
- : DEFAULT TARGET EQ_ ((LP_ containerName RP_) | NONE)
- | HOST EQ_ hostName
- | PORT EQ_ NUMBER_
- ;
-
pdbStorageClause
: STORAGE ((LP_ storageMaxSizeClauses+ RP_) | UNLIMITED)
;
diff --git
a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DMLStatement.g4
b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DMLStatement.g4
index 6d20e9d578c..f8444a02303 100644
--- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DMLStatement.g4
+++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DMLStatement.g4
@@ -17,7 +17,7 @@
grammar DMLStatement;
-import Comments, DDLStatement;
+import Comments, BaseRule;
insert
: INSERT hint? (insertSingleTable | insertMultiTable)
@@ -478,8 +478,7 @@ queryTableExprSampleClause
: (queryTableExprTableClause
| queryTableExprViewClause
| hierarchyName
- | queryTableExprAnalyticClause
- | (owner DOT_)? inlineExternalTable) sampleClause?
+ | queryTableExprAnalyticClause) sampleClause?
;
queryTableExprTableClause
@@ -494,10 +493,6 @@ queryTableExprAnalyticClause
: analyticViewName (HIERARCHIES LP_ ((attrDim DOT_)? hierarchyName (COMMA_
(attrDim DOT_)? hierarchyName)*)? RP_)?
;
-inlineExternalTable
- : EXTERNAL LP_ LP_ columnDefinition (COMMA_ columnDefinition)* RP_
inlineExternalTableProperties RP_
- ;
-
inlineExternalTableProperties
: (TYPE accessDriverType)? externalTableDataProperties (REJECT LIMIT
(INTEGER_ | UNLIMITED))?
;
diff --git
a/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4
b/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4
index 8fc55aa20a9..31c8bcd7b6f 100644
---
a/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4
+++
b/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4
@@ -17,7 +17,7 @@
grammar OracleStatement;
-import DMLStatement, TCLStatement, DCLStatement, DALStatement, PLSQL;
+import DDLStatement, TCLStatement, DCLStatement, DALStatement, PLSQL;
execute
: (select
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 41a5308aa82..521c7c3cdef 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
@@ -2032,4 +2032,8 @@
<referenced-table name="warehouse_table" start-index="89"
stop-index="103" />
</column-definition>
</create-table>
+
+ <create-table sql-case-id="create_table_with_select">
+ <table name="t_order_new" start-index="13" stop-index="23"/>
+ </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 c54d8c9d0d7..d9bfa0a1a65 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
@@ -149,4 +149,5 @@
<sql-case id="create_table_with_partition_less_than" value="CREATE TABLE
t_sales (order_id INTEGER NOT NULL, goods_name CHAR(20) NOT NULL, sales_date
DATE NOT NULL, sales_volume INTEGER, sales_store CHAR(20), PRIMARY KEY (
order_id )) PARTITION BY RANGE (sales_date) (PARTITION season1 VALUES LESS
THAN('2023-04-01 00:00:00'),PARTITION season2 VALUES LESS THAN('2023-07-01
00:00:00'),PARTITION season3 VALUES LESS THAN('2023-10-01 00:00:00'),PARTITION
season4 VALUES LESS THAN(MAXVALUE))" [...]
<sql-case id="create_table_with_negative_data_type" value="CREATE TABLE
T(COL1 NUMBER, COL2 NUMBER(3), COL3 NUMBER(3,2), COL4 NUMBER(6,-2))"
db-types="Oracle" />
<sql-case id="create_table_with_ref_data_type" value="CREATE TABLE
location_table (location_number NUMBER, building REF warehouse_typ SCOPE IS
warehouse_table);" db-types="Oracle" />
+ <sql-case id="create_table_with_select" value="CREATE TABLE t_order_new AS
SELECT * FROM t_order" db-types="Oracle"/>
</sql-cases>