Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
b82de018
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
b82de018
编写于
5月 12, 2020
作者:
J
JingShang Lu
提交者:
GitHub
5月 12, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix g4 file of mysql ddl (#5533)
上级
473aa3c5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
111 addition
and
50 deletion
+111
-50
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/BaseRule.g4
...ql-parser-mysql/src/main/antlr4/imports/mysql/BaseRule.g4
+8
-0
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DDLStatement.g4
...arser-mysql/src/main/antlr4/imports/mysql/DDLStatement.g4
+87
-49
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/impl/MySQLDDLVisitor.java
...sphere/sql/parser/mysql/visitor/impl/MySQLDDLVisitor.java
+16
-1
未找到文件。
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/BaseRule.g4
浏览文件 @
b82de018
...
...
@@ -579,3 +579,11 @@ ignoredIdentifiers_
fieldOrVarSpec
: LP_ (identifier (COMMA_ identifier)*)? RP_
;
notExistClause_
: (IF NOT EXISTS)?
;
existClause_
: (IF EXISTS)?
;
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DDLStatement.g4
浏览文件 @
b82de018
...
...
@@ -20,20 +20,56 @@ grammar DDLStatement;
import Symbol, Keyword, MySQLKeyword, Literals, BaseRule, DMLStatement;
createTable
: CREATE createTableSpecification_? TABLE
tableNotExistClause_ tableName (createDefinitionClause
| createLikeClause)
: CREATE createTableSpecification_? TABLE
notExistClause_ tableName (createDefinitionClause tableOptions_? partitionOptions? (AS? select)?
| createLikeClause)
;
alterTable
: ALTER TABLE tableName alterDefinitionClause?
: ALTER TABLE tableName alterDefinitionClause? partitionOption?
;
partitionOptions
:partitionOption partitionOption*
;
partitionOption
: ADD PARTITION LP_ partitionDefinition_ RP_
| DROP PARTITION partitionNames
| DISCARD PARTITION (partitionNames | ALL) TABLESPACE
| IMPORT PARTITION (partitionNames | ALL) TABLESPACE
| TRUNCATE PARTITION (partitionNames | ALL)
| COALESCE PARTITION NUMBER_
| REORGANIZE PARTITION partitionNames INTO LP_ partitionDefinitions_ RP_
| EXCHANGE PARTITION partitionName WITH TABLE tableName ((WITH | WITHOUT) VALIDATION)
| ANALYZE PARTITION (partitionNames | ALL)
| CHECK PARTITION (partitionNames | ALL)
| OPTIMIZE PARTITION (partitionNames | ALL)
| REBUILD PARTITION (partitionNames | ALL)
| REPAIR PARTITION (partitionNames | ALL)
| REMOVE PARTITIONING
| PARTITION BY (LINEAR? HASH LP_ expr RP_ | LINEAR? KEY (ALGORITHM EQ_ NUMBER_)? LP_ columnNames RP_ | RANGE (LP_ expr RP_ | COLUMNS LP_ columnNames RP_) |
LIST (LP_ expr RP_ | COLUMNS LP_ columnNames RP_)) (PARTITIONS NUMBER_)?
(SUBPARTITION BY (LINEAR? HASH LP_ expr RP_ | LINEAR? KEY (ALGORITHM EQ_ NUMBER_ LP_ columnNames RP_)) (SUBPARTITIONS NUMBER_)?)? partitionDefinitions_?
;
partitionNames
: partitionName (COMMA_ partitionName)*
;
dropTable
: DROP dropTableSpecification_ TABLE
tableExistClause_ tableNames
: DROP dropTableSpecification_ TABLE
existClause_ tableNames (RESTRICT | CASCADE)?
;
dropIndex
: DROP INDEX dropIndexSpecification_? indexName (ON tableName)?
( ALGORITHM EQ_? (DEFAULT | INPLACE | COPY) | LOCK EQ_? (DEFAULT | NONE | SHARED | EXCLUSIVE) )*
: DROP INDEX indexName (ON tableName)?
(algorithmOption | lockOption)*
;
algorithmOption
: ALGORITHM EQ_? (DEFAULT | INPLACE | COPY)
;
lockOption
: LOCK EQ_? (DEFAULT | NONE | SHARED | EXCLUSIVE)
;
truncateTable
...
...
@@ -42,14 +78,11 @@ truncateTable
createIndex
: CREATE createIndexSpecification_ INDEX indexName indexType_? ON tableName keyParts_ indexOption_?
(
ALGORITHM EQ_? (DEFAULT | INPLACE | COPY)
| LOCK EQ_? (DEFAULT | NONE | SHARED | EXCLUSIVE)
)*
(algorithmOption | lockOption)*
;
createDatabase
: CREATE (DATABASE | SCHEMA)
(IF NOT EXISTS)
? schemaName createDatabaseSpecification_*
: CREATE (DATABASE | SCHEMA)
notExistClause_
? schemaName createDatabaseSpecification_*
;
alterDatabase
...
...
@@ -63,7 +96,7 @@ createDatabaseSpecification_
;
dropDatabase
: DROP (DATABASE | SCHEMA)
(IF EXISTS)?
schemaName
: DROP (DATABASE | SCHEMA)
existClause_
schemaName
;
alterInstance
...
...
@@ -72,11 +105,15 @@ alterInstance
;
instanceAction
: ROTATE INNODB_ MASTER KEY | ROTATE BINLOG MASTER KEY | RELOAD TLS_ (NO ROLLBACK ON ERROR)?
: ROTATE INNODB_ MASTER KEY | ROTATE BINLOG MASTER KEY | RELOAD TLS_ (FOR CHANNEL channel)? (NO ROLLBACK ON ERROR)?
;
channel
: 'mysql_admin' | 'mysql_main'
;
createEvent
: CREATE ownerStatement? EVENT
(IF NOT EXISTS)
? eventName
: CREATE ownerStatement? EVENT
notExistClause_
? eventName
ON SCHEDULE scheduleExpression_
(ON COMPLETION NOT? PRESERVE)?
(ENABLE | DISABLE | DISABLE ON SLAVE)?
...
...
@@ -94,7 +131,7 @@ alterEvent
;
dropEvent
: DROP EVENT
(IF EXISTS)?
eventName
: DROP EVENT
existClause_
eventName
;
createFunction
...
...
@@ -110,7 +147,7 @@ alterFunction
;
dropFunction
: DROP FUNCTION
(IF EXISTS)
functionName
: DROP FUNCTION
existClause_
functionName
;
createProcedure
...
...
@@ -125,7 +162,7 @@ alterProcedure
;
dropProcedure
: DROP PROCEDURE
(IF EXISTS)?
functionName
: DROP PROCEDURE
existClause_
functionName
;
createServer
...
...
@@ -140,32 +177,30 @@ alterServer
;
dropServer
: DROP SERVER
(IF EXISTS)?
serverName
: DROP SERVER
existClause_
serverName
;
createView
: CREATE (OR REPLACE)?
(
ALGORITHM EQ_ (UNDEFINED | MERGE | TEMPTABLE)
)?
(
ALGORITHM EQ_ (UNDEFINED | MERGE | TEMPTABLE)
)?
ownerStatement?
(SQL SECURITY (DEFINER | INVOKER))?
VIEW viewName (LP_
identifier (COMMA_ identifier)* RP_)?
VIEW viewName (LP_
columnNames RP_)?
AS select
(WITH (CASCADED | LOCAL)? CHECK OPTION)?
;
alterView
: ALTER
( ALGORITHM EQ_ (UNDEFINED | MERGE | TEMPTABLE) )?
: ALTER (ALGORITHM EQ_ (UNDEFINED | MERGE | TEMPTABLE))?
ownerStatement?
(SQL SECURITY (DEFINER | INVOKER))?
VIEW viewName (LP_
identifier (COMMA_ identifier)* RP_)?
VIEW viewName (LP_
columnNames RP_)?
AS select
(WITH (CASCADED | LOCAL)? CHECK OPTION)?
;
dropView
: DROP VIEW (IF EXISTS)?
viewName (COMMA_ viewName)* (RESTRICT | CASCADE)?
: DROP VIEW existClause_ viewName (COMMA_ viewName)* (RESTRICT | CASCADE)?
;
createTablespaceInnodb
...
...
@@ -187,19 +222,26 @@ createTablespaceNdb
(NODEGROUP EQ_? identifier)?
WAIT?
(COMMENT EQ_? STRING_)?
ENGINE EQ_? identifier
(ENGINE EQ_? identifier)?
;
alterTablespace
: ALTER TABLESPACE identifier
alterTablespace
Ndb
: ALTER
UNDO?
TABLESPACE identifier
(ADD | DROP) DATAFILE STRING_
(INITIAL_SIZE EQ_ fileSizeLiteral_)?
WAIT?
ENGINE EQ_? identifier
WAIT? (RENAME TO identifier)?
(ENGINE EQ_? identifier)?
;
alterTablespaceInnodb
: ALTER UNDO? TABLESPACE identifier
(SET (ACTIVE | INACTIVE))? (ENCRYPTION EQ_? Y_N_)
(RENAME TO identifier)?
(ENGINE EQ_? identifier)?
;
dropTablespace
: DROP TABLESPACE identifier (ENGINE EQ_? identifier)?
: DROP
UNDO?
TABLESPACE identifier (ENGINE EQ_? identifier)?
;
createLogfileGroup
...
...
@@ -222,19 +264,23 @@ alterLogfileGroup
;
dropLogfileGroup
: DROP LOGFILE GROUP identifier ENGINE EQ_ identifier
: DROP LOGFILE GROUP identifier ENGINE EQ_
?
identifier
;
createTrigger
: CREATE ownerStatement? TRIGGER triggerName triggerTime triggerEvent ON tableName FOR EACH ROW triggerOrder? routineBody
;
createTableSpecification_
: TEMPORARY
dropTrigger
: DROP TRIGGER existClause_ (schemaName DOT_)? triggerName
;
renameTable
: RENAME TABLE tableName TO tableName (tableName TO tableName)*
;
tableNotExistClause
_
:
(IF NOT EXISTS)?
createTableSpecification
_
:
TEMPORARY
;
createDefinitionClause
...
...
@@ -268,7 +314,7 @@ dataTypeGenericOption
;
checkConstraintDefinition
: (CONSTRAINT ignoredIdentifier_?)? CHECK
expr
(NOT? ENFORCED)?
: (CONSTRAINT ignoredIdentifier_?)? CHECK
LP_ expr RP_
(NOT? ENFORCED)?
;
referenceDefinition
...
...
@@ -308,7 +354,7 @@ constraintDefinition
;
primaryKeyOption
: primaryKey indexType_?
columnNames
indexOption_*
: primaryKey indexType_?
keyParts_
indexOption_*
;
primaryKey
...
...
@@ -344,7 +390,7 @@ alterSpecification
| DROP CHECK ignoredIdentifier_
| ALTER CHECK ignoredIdentifier_ NOT? ENFORCED
| ALGORITHM EQ_? (DEFAULT | INSTANT | INPLACE | COPY)
| ALTER COLUMN? columnName (SET DEFAULT
literals
| DROP DEFAULT)
| ALTER COLUMN? columnName (SET DEFAULT
(literals | LP_ expr RP_)
| DROP DEFAULT)
| ALTER INDEX indexName (VISIBLE | INVISIBLE)
| changeColumnSpecification
| modifyColumnSpecification
...
...
@@ -357,7 +403,7 @@ alterSpecification
| dropPrimaryKeySpecification
| DROP FOREIGN KEY ignoredIdentifier_
| FORCE
|
LOCK EQ_? (DEFAULT | NONE | SHARED | EXCLUSIVE)
|
lockOption
// TODO investigate ORDER BY col_name [, col_name] ...
| ORDER BY columnNames
| renameColumnSpecification
...
...
@@ -465,7 +511,7 @@ partitionDefinitions_
;
partitionDefinition_
: PARTITION
identifier
: PARTITION
partitionName
(VALUES (LESS THAN partitionLessThanValue_ | IN LP_ partitionValueList_ RP_))?
partitionDefinitionOption_*
(LP_ subpartitionDefinition_ (COMMA_ subpartitionDefinition_)* RP_)?
...
...
@@ -497,14 +543,6 @@ dropTableSpecification_
: TEMPORARY?
;
tableExistClause_
: (IF EXISTS)?
;
dropIndexSpecification_
: ONLINE | OFFLINE
;
ownerStatement
: DEFINER EQ_ (userName | CURRENT_USER ( '(' ')')?)
;
...
...
@@ -538,7 +576,7 @@ routineOption_
: COMMENT STRING_
| LANGUAGE SQL
| NOT? DETERMINISTIC
| (
CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA)
| (
CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA)
| SQL SECURITY (DEFINER | INVOKER)
;
...
...
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/impl/MySQLDDLVisitor.java
浏览文件 @
b82de018
...
...
@@ -21,6 +21,8 @@ import com.google.common.base.Preconditions;
import
org.antlr.v4.runtime.Token
;
import
org.apache.shardingsphere.sql.parser.api.ASTNode
;
import
org.apache.shardingsphere.sql.parser.api.visitor.statement.DDLVisitor
;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.KeyPart_Context
;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.KeyParts_Context
;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AddColumnSpecificationContext
;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AlterDefinitionClauseContext
;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AlterSpecificationContext
;
...
...
@@ -83,6 +85,7 @@ import org.apache.shardingsphere.sql.parser.sql.value.collection.CollectionValue
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.LinkedList
;
import
java.util.List
;
/**
* DDL visitor for MySQL.
...
...
@@ -267,7 +270,7 @@ public final class MySQLDDLVisitor extends MySQLVisitor implements DDLVisitor {
public
ASTNode
visitConstraintDefinition
(
final
ConstraintDefinitionContext
ctx
)
{
ConstraintDefinitionSegment
result
=
new
ConstraintDefinitionSegment
(
ctx
.
getStart
().
getStartIndex
(),
ctx
.
getStop
().
getStopIndex
());
if
(
null
!=
ctx
.
primaryKeyOption
())
{
result
.
getPrimaryKeyColumns
().
addAll
(((
CollectionValue
<
ColumnSegment
>)
visit
(
ctx
.
primaryKeyOption
().
columnNames
())).
getValue
());
result
.
getPrimaryKeyColumns
().
addAll
(((
CollectionValue
<
ColumnSegment
>)
visit
(
ctx
.
primaryKeyOption
().
keyParts_
())).
getValue
());
}
if
(
null
!=
ctx
.
foreignKeyOption
())
{
result
.
setReferencedTable
((
SimpleTableSegment
)
visit
(
ctx
.
foreignKeyOption
().
referenceDefinition
()));
...
...
@@ -371,4 +374,16 @@ public final class MySQLDDLVisitor extends MySQLVisitor implements DDLVisitor {
result
.
setTable
((
SimpleTableSegment
)
visit
(
ctx
.
tableName
()));
return
result
;
}
@Override
public
ASTNode
visitKeyParts_
(
final
KeyParts_Context
ctx
)
{
CollectionValue
<
ColumnSegment
>
result
=
new
CollectionValue
<>();
List
<
KeyPart_Context
>
keyparts
=
ctx
.
keyPart_
();
for
(
KeyPart_Context
each
:
keyparts
)
{
if
(
null
!=
each
.
columnName
())
{
result
.
getValue
().
add
((
ColumnSegment
)
visit
(
each
.
columnName
()));
}
}
return
result
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录