You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/02/08 03:29:29 UTC
[shardingsphere] branch master updated: modify grammar of the
"create index" (#9357)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 39e06bc modify grammar of the "create index" (#9357)
39e06bc is described below
commit 39e06bc0ba2a1b9efec601165719b947e9d4cce5
Author: coco <co...@gmail.com>
AuthorDate: Mon Feb 8 11:29:12 2021 +0800
modify grammar of the "create index" (#9357)
* feature: create index in oracle.
* test: add unit tests in create index.
---
.../src/main/antlr4/imports/oracle/BaseRule.g4 | 4 +++
.../src/main/antlr4/imports/oracle/DDLStatement.g4 | 20 +++++++++--
.../main/antlr4/imports/oracle/OracleKeyword.g4 | 12 +++++++
.../impl/OracleDDLStatementSQLVisitor.java | 2 +-
.../src/main/resources/case/ddl/create-index.xml | 39 ++++++++++++++++++++++
.../main/resources/sql/supported/ddl/create.xml | 6 ++++
6 files changed, 80 insertions(+), 3 deletions(-)
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/BaseRule.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/BaseRule.g4
index cd995e1..1223a6d 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/BaseRule.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/BaseRule.g4
@@ -115,6 +115,10 @@ objectName
: (owner DOT_)? name
;
+clusterName
+ : (owner DOT_)? name
+ ;
+
indexName
: identifier
;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4
index 66e4963..a1592d2 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4
@@ -24,7 +24,7 @@ createTable
;
createIndex
- : CREATE createIndexSpecification INDEX indexName ON createIndexDefinitionClause
+ : CREATE createIndexSpecification INDEX indexName ON createIndexDefinitionClause usableSpecification? invalidationSpecification?
;
alterTable
@@ -200,6 +200,14 @@ createIndexSpecification
: (UNIQUE | BITMAP)?
;
+clusterIndexClause
+ : CLUSTER clusterName indexAttributes?
+ ;
+
+indexAttributes
+ : (ONLINE | (SORT|NOSORT) | REVERSE | (VISIBLE | INVISIBLE))
+ ;
+
tableIndexClause
: tableName alias? indexExpressions
;
@@ -225,7 +233,7 @@ columnSortClause_
;
createIndexDefinitionClause
- : tableIndexClause | bitmapJoinIndexClause
+ : clusterIndexClause | tableIndexClause | bitmapJoinIndexClause
;
tableAlias
@@ -395,6 +403,14 @@ enableDisableOthers
: (ENABLE | DISABLE) (TABLE LOCK | ALL TRIGGERS | CONTAINER_MAP | CONTAINERS_DEFAULT)
;
+usableSpecification
+ : (USABLE | UNUSABLE)
+ ;
+
+invalidationSpecification
+ : (DEFERRED | IMMEDIATE) INVALIDATION
+ ;
+
materializedViewLogClause
: (PRESERVE | PURGE) MATERIALIZED VIEW LOG
;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4
index c0881d2..22e6cac 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4
@@ -839,6 +839,18 @@ BATCH
: B A T C H
;
+USABLE
+ : U S A B L E
+ ;
+
+UNUSABLE
+ : U N U S A B L E
+ ;
+
+INVALIDATION
+ : I N V A L I D A T I O N
+ ;
+
LOG
: L O G
;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDDLStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDDLStatementSQLVisitor.java
index f813641..5c1716c 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDDLStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDDLStatementSQLVisitor.java
@@ -265,8 +265,8 @@ public final class OracleDDLStatementSQLVisitor extends OracleStatementSQLVisito
OracleCreateIndexStatement result = new OracleCreateIndexStatement();
if (null != ctx.createIndexDefinitionClause().tableIndexClause()) {
result.setTable((SimpleTableSegment) visit(ctx.createIndexDefinitionClause().tableIndexClause().tableName()));
- result.setIndex((IndexSegment) visit(ctx.indexName()));
}
+ result.setIndex((IndexSegment) visit(ctx.indexName()));
return result;
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/create-index.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/create-index.xml
index bdcd977..177b167 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/create-index.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/create-index.xml
@@ -101,6 +101,45 @@
</table>
</create-index>
+ <create-index sql-case-id="create_index_with_unique">
+ <table>
+ <simple-table name="t_order" start-index="35" stop-index="41" />
+ </table>
+ <index name="order_index" start-index="20" stop-index="30" />
+ </create-index>
+
+ <create-index sql-case-id="create_index_with_usable">
+ <table>
+ <simple-table name="t_order" start-index="35" stop-index="41" />
+ </table>
+ <index name="order_index" start-index="20" stop-index="30" />
+ </create-index>
+
+ <create-index sql-case-id="create_index_with_unusable">
+ <table>
+ <simple-table name="t_order" start-index="35" stop-index="41" />
+ </table>
+ <index name="order_index" start-index="20" stop-index="30" />
+ </create-index>
+
+ <create-index sql-case-id="create_index_with_immediate_invalidation">
+ <table>
+ <simple-table name="t_order" start-index="35" stop-index="41" />
+ </table>
+ <index name="order_index" start-index="20" stop-index="30" />
+ </create-index>
+
+ <create-index sql-case-id="create_index_with_cluster_index">
+ <index name="order_index" start-index="20" stop-index="30" />
+ </create-index>
+
+ <create-index sql-case-id="create_index_with_bitmap">
+ <table>
+ <simple-table name="t_order" start-index="35" stop-index="41" />
+ </table>
+ <index name="order_index" start-index="20" stop-index="30" />
+ </create-index>
+
<create-index sql-case-id="create_index_with_bracket">
<table>
<simple-table name="t_order" start-delimiter="[" end-delimiter="]" start-index="30" stop-index="38" />
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/create.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/create.xml
index f31aabb..3ac9f2a 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/create.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/create.xml
@@ -136,6 +136,12 @@
<sql-case id="create_index_concurrently" value="CREATE INDEX CONCURRENTLY order_index ON t_order (order_id)" db-types="PostgreSQL" />
<sql-case id="create_index_if_not_exists" value="CREATE INDEX IF NOT EXISTS order_index ON t_order (order_id)" db-types="PostgreSQL" />
<sql-case id="create_index_using_btree" value="CREATE INDEX order_index ON t_order (order_id) USING BTREE" db-types="PostgreSQL" />
+ <sql-case id="create_index_with_unique" value="CREATE UNIQUE INDEX order_index ON t_order (order_id)" db-types="Oracle" />
+ <sql-case id="create_index_with_usable" value="CREATE UNIQUE INDEX order_index ON t_order (order_id) USABLE" db-types="Oracle" />
+ <sql-case id="create_index_with_unusable" value="CREATE UNIQUE INDEX order_index ON t_order (order_id) UNUSABLE" db-types="Oracle" />
+ <sql-case id="create_index_with_immediate_invalidation" value="CREATE UNIQUE INDEX order_index ON t_order (order_id) IMMEDIATE INVALIDATION" db-types="Oracle" />
+ <sql-case id="create_index_with_cluster_index" value="CREATE UNIQUE INDEX order_index ON CLUSTER t_cluster" db-types="Oracle" />
+ <sql-case id="create_index_with_bitmap" value="CREATE BITMAP INDEX order_index ON t_order (order_id)" db-types="Oracle" />
<!-- create database test-->
<sql-case id="create_database" value="CREATE DATABASE lusiadas" db-types="PostgreSQL" />