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

jianglongtao 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 057204f  For #13994, Add `CREATE SHARDING KEY GENERATOR` syntax to 
DistSQL. (#14056)
057204f is described below

commit 057204f6fca073cc079f3178d690425842c5f350
Author: yx9o <[email protected]>
AuthorDate: Mon Dec 13 11:14:59 2021 +0800

    For #13994, Add `CREATE SHARDING KEY GENERATOR` syntax to DistSQL. (#14056)
    
    * DistSQL to support CREATE SHARDING KEY GENERATOR
    
    * Update
    
    * Update
    
    * Update
    
    * Update
---
 ...CreateShardingKeyGeneratorStatementUpdater.java | 105 +++++++++++++++++++++
 ...here.infra.distsql.update.RuleDefinitionUpdater |   1 +
 ...teShardingKeyGeneratorStatementUpdaterTest.java |  97 +++++++++++++++++++
 .../src/main/antlr4/imports/sharding/Keyword.g4    |   7 ++
 .../main/antlr4/imports/sharding/RDLStatement.g4   |  12 +++
 .../parser/autogen/ShardingDistSQLStatement.g4     |   1 +
 .../core/ShardingDistSQLStatementVisitor.java      |  15 ++-
 .../segment/ShardingKeyGeneratorSegment.java       |  35 +++++++
 .../CreateShardingKeyGeneratorStatement.java       |  35 +++++++
 .../rule/DuplicateKeyGeneratorException.java       |  32 +++++++
 .../rdl/create/CreateRuleStatementAssert.java      |   7 +-
 .../CreateShardingKeyGeneratorStatementAssert.java |  75 +++++++++++++++
 .../jaxb/cases/domain/SQLParserTestCases.java      |   5 +
 .../distsql/rdl/ExpectedShardingKeyGenerator.java  |  40 ++++++++
 ...reateShardingKeyGeneratorStatementTestCase.java |  38 ++++++++
 .../src/main/resources/case/rdl/create.xml         |  24 +++--
 .../main/resources/sql/supported/rdl/create.xml    |   1 +
 17 files changed, 521 insertions(+), 9 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingKeyGeneratorStatementUpdater.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingKeyGeneratorStatementUpdater.java
new file mode 100644
index 0000000..d2e39d7
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingKeyGeneratorStatementUpdater.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.distsql.handler.update;
+
+import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
+import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
+import 
org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateKeyGeneratorException;
+import 
org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException;
+import 
org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.distsql.handler.converter.ShardingTableRuleStatementConverter;
+import 
org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingKeyGeneratorSegment;
+import 
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingKeyGeneratorStatement;
+import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
+import org.apache.shardingsphere.spi.typed.TypedSPIRegistry;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * Create sharding key generator statement updater.
+ */
+public final class CreateShardingKeyGeneratorStatementUpdater implements 
RuleDefinitionCreateUpdater<CreateShardingKeyGeneratorStatement, 
ShardingRuleConfiguration> {
+    
+    @Override
+    public void checkSQLStatement(final ShardingSphereMetaData 
shardingSphereMetaData, final CreateShardingKeyGeneratorStatement sqlStatement,
+                                  final ShardingRuleConfiguration 
currentRuleConfig) throws DistSQLException {
+        checkDuplicate(shardingSphereMetaData.getName(), sqlStatement, 
currentRuleConfig);
+        checkKeyGeneratorAlgorithm(sqlStatement);
+    }
+    
+    private void checkDuplicate(final String schemaName, final 
CreateShardingKeyGeneratorStatement sqlStatement, final 
ShardingRuleConfiguration currentRuleConfig) throws DistSQLException {
+        LinkedList<String> keyGeneratorNames = 
sqlStatement.getKeyGeneratorSegments().stream()
+                
.map(ShardingKeyGeneratorSegment::getKeyGeneratorName).collect(Collectors.toCollection(LinkedList::new));
+        checkDuplicateInput(keyGeneratorNames, duplicated -> new 
DuplicateKeyGeneratorException("sharding", schemaName, duplicated));
+        if (null != currentRuleConfig) {
+            checkExist(keyGeneratorNames, 
currentRuleConfig.getKeyGenerators().keySet(), duplicated -> new 
DuplicateKeyGeneratorException("sharding", schemaName, duplicated));
+        }
+    }
+    
+    private void checkDuplicateInput(final Collection<String> rules, final 
Function<Set<String>, DistSQLException> thrower) throws DistSQLException {
+        Set<String> duplicateRequire = 
rules.stream().collect(Collectors.groupingBy(each -> each, 
Collectors.counting())).entrySet().stream()
+                .filter(each -> each.getValue() > 
1).map(Map.Entry::getKey).collect(Collectors.toSet());
+        DistSQLException.predictionThrow(duplicateRequire.isEmpty(), 
thrower.apply(duplicateRequire));
+    }
+    
+    private void checkExist(final Collection<String> requireRules, final 
Collection<String> currentRules, final Function<Set<String>, DistSQLException> 
thrower) throws DistSQLException {
+        Set<String> identical = 
requireRules.stream().filter(currentRules::contains).collect(Collectors.toSet());
+        DistSQLException.predictionThrow(identical.isEmpty(), 
thrower.apply(identical));
+    }
+    
+    private void checkKeyGeneratorAlgorithm(final 
CreateShardingKeyGeneratorStatement sqlStatement) throws DistSQLException {
+        Collection<String> notExistedKeyGeneratorAlgorithms = 
sqlStatement.getKeyGeneratorSegments().stream().map(ShardingKeyGeneratorSegment::getAlgorithmSegment).map(AlgorithmSegment::getName)
+                .filter(each -> 
!TypedSPIRegistry.findRegisteredService(KeyGenerateAlgorithm.class, each, new 
Properties()).isPresent()).collect(Collectors.toList());
+        
DistSQLException.predictionThrow(notExistedKeyGeneratorAlgorithms.isEmpty(), 
new InvalidAlgorithmConfigurationException("sharding", 
notExistedKeyGeneratorAlgorithms));
+    }
+    
+    @Override
+    public ShardingRuleConfiguration buildToBeCreatedRuleConfiguration(final 
CreateShardingKeyGeneratorStatement sqlStatement) {
+        ShardingRuleConfiguration result = new ShardingRuleConfiguration();
+        Map<String, ShardingSphereAlgorithmConfiguration> 
keyGeneratorConfigurationMap = sqlStatement.getKeyGeneratorSegments().stream()
+                
.collect(Collectors.toMap(ShardingKeyGeneratorSegment::getKeyGeneratorName, 
each -> 
ShardingTableRuleStatementConverter.createAlgorithmConfiguration(each.getAlgorithmSegment())));
+        result.setKeyGenerators(keyGeneratorConfigurationMap);
+        return result;
+    }
+    
+    @Override
+    public void updateCurrentRuleConfiguration(final ShardingRuleConfiguration 
currentRuleConfig, final ShardingRuleConfiguration toBeCreatedRuleConfig) {
+        if (null != currentRuleConfig) {
+            
currentRuleConfig.getKeyGenerators().putAll(toBeCreatedRuleConfig.getKeyGenerators());
+        }
+    }
+    
+    @Override
+    public Class<ShardingRuleConfiguration> getRuleConfigurationClass() {
+        return ShardingRuleConfiguration.class;
+    }
+    
+    @Override
+    public String getType() {
+        return CreateShardingKeyGeneratorStatement.class.getCanonicalName();
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
index 160b5ea..6cf7865 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
@@ -28,3 +28,4 @@ 
org.apache.shardingsphere.sharding.distsql.handler.update.AlterShardingBroadcast
 
org.apache.shardingsphere.sharding.distsql.handler.update.DropShardingBroadcastTableRuleStatementUpdater
 
org.apache.shardingsphere.sharding.distsql.handler.update.CreateDefaultShardingStrategyStatementUpdater
 
org.apache.shardingsphere.sharding.distsql.handler.update.AlterShardingAlgorithmStatementUpdater
+org.apache.shardingsphere.sharding.distsql.handler.update.CreateShardingKeyGeneratorStatementUpdater
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingKeyGeneratorStatementUpdaterTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingKeyGeneratorStatementUpdaterTest.java
new file mode 100644
index 0000000..687df62
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingKeyGeneratorStatementUpdaterTest.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.distsql.update;
+
+import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
+import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
+import 
org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateKeyGeneratorException;
+import 
org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.distsql.handler.update.CreateShardingKeyGeneratorStatementUpdater;
+import 
org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingKeyGeneratorSegment;
+import 
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingKeyGeneratorStatement;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.util.Arrays;
+import java.util.Properties;
+
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class CreateShardingKeyGeneratorStatementUpdaterTest {
+    
+    @Mock
+    private ShardingSphereMetaData shardingSphereMetaData;
+    
+    private CreateShardingKeyGeneratorStatementUpdater updater;
+    
+    @Before
+    public void before() {
+        updater = new CreateShardingKeyGeneratorStatementUpdater();
+        when(shardingSphereMetaData.getName()).thenReturn("test");
+    }
+    
+    @Test(expected = DuplicateKeyGeneratorException.class)
+    public void assertExecuteWithDuplicate() throws DistSQLException {
+        ShardingKeyGeneratorSegment keyGeneratorSegment = 
buildShardingKeyGeneratorSegment();
+        updater.checkSQLStatement(shardingSphereMetaData, 
createSQLStatement(keyGeneratorSegment, keyGeneratorSegment), null);
+    }
+    
+    @Test(expected = DuplicateKeyGeneratorException.class)
+    public void assertExecuteWithExist() throws DistSQLException {
+        ShardingKeyGeneratorSegment keyGeneratorSegment = 
buildShardingKeyGeneratorSegment();
+        ShardingRuleConfiguration shardingRuleConfiguration = new 
ShardingRuleConfiguration();
+        shardingRuleConfiguration.getKeyGenerators().put("uuid_key_generator", 
new ShardingSphereAlgorithmConfiguration("uuid", buildProps()));
+        updater.checkSQLStatement(shardingSphereMetaData, 
createSQLStatement(keyGeneratorSegment), shardingRuleConfiguration);
+    }
+    
+    @Test(expected = InvalidAlgorithmConfigurationException.class)
+    public void assertExecuteWithoutRuleConfiguration() throws 
DistSQLException {
+        ShardingKeyGeneratorSegment keyGeneratorSegment = 
buildShardingKeyGeneratorSegment();
+        ShardingRuleConfiguration shardingRuleConfiguration = null;
+        updater.checkSQLStatement(shardingSphereMetaData, 
createSQLStatement(keyGeneratorSegment), shardingRuleConfiguration);
+    }
+    
+    @Test(expected = InvalidAlgorithmConfigurationException.class)
+    public void assertExecuteWithInvalidAlgorithm() throws DistSQLException {
+        ShardingKeyGeneratorSegment keyGeneratorSegment = 
buildShardingKeyGeneratorSegment();
+        ShardingRuleConfiguration shardingRuleConfiguration = new 
ShardingRuleConfiguration();
+        
shardingRuleConfiguration.getKeyGenerators().put("snowflake_key_generator", new 
ShardingSphereAlgorithmConfiguration("INVALID_ALGORITHM", buildProps()));
+        updater.checkSQLStatement(shardingSphereMetaData, 
createSQLStatement(keyGeneratorSegment), shardingRuleConfiguration);
+    }
+    
+    private CreateShardingKeyGeneratorStatement createSQLStatement(final 
ShardingKeyGeneratorSegment... ruleSegments) {
+        return new 
CreateShardingKeyGeneratorStatement(Arrays.asList(ruleSegments));
+    }
+    
+    private ShardingKeyGeneratorSegment buildShardingKeyGeneratorSegment() {
+        return new ShardingKeyGeneratorSegment("uuid_key_generator", new 
AlgorithmSegment("uuid", buildProps()));
+    }
+    
+    private Properties buildProps() {
+        Properties props = new Properties();
+        props.put("worker-id", "123");
+        return props;
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/Keyword.g4
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/Keyword.g4
index 987b3e5..4395ee6 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/Keyword.g4
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/Keyword.g4
@@ -171,3 +171,10 @@ NODES
     : N O D E S
     ;
 
+KEY
+    : K E Y
+    ;
+
+GENERATOR
+    : G E N E R A T O R
+    ;
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/RDLStatement.g4
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/RDLStatement.g4
index 85c1b77c..b25fef2 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/RDLStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/RDLStatement.g4
@@ -39,6 +39,10 @@ createDefaultShardingStrategy
     : CREATE DEFAULT SHARDING type=(DATABASE | TABLE) STRATEGY LP 
shardingStrategy RP
     ;
 
+createShardingKeyGenerator
+    : CREATE SHARDING KEY GENERATOR keyGeneratorDefination (COMMA 
keyGeneratorDefination)*
+    ;
+
 alterShardingTableRule
     : ALTER SHARDING TABLE RULE shardingTableRuleDefinition (COMMA 
shardingTableRuleDefinition)*
     ;
@@ -162,3 +166,11 @@ algorithmProperties
 algorithmProperty
     : key=(IDENTIFIER | STRING) EQ value=(NUMBER | INT | IDENTIFIER | STRING)
     ;
+
+keyGeneratorDefination
+    : keyGeneratorName LP algorithmDefinition RP
+    ;
+
+keyGeneratorName
+    : IDENTIFIER
+    ;    
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingDistSQLStatement.g4
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingDistSQLStatement.g4
index 87210c5..854df10 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingDistSQLStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingDistSQLStatement.g4
@@ -43,5 +43,6 @@ execute
     | createShardingAlgorithm
     | alterShardingAlgorithm
     | showShardingTableNodes
+    | createShardingKeyGenerator
     ) SEMI?
     ;
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java
index 89f3997..43068c4 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java
@@ -34,6 +34,7 @@ import 
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatement
 import 
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.CreateShardingAlgorithmContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.CreateShardingBindingTableRulesContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.CreateShardingBroadcastTableRulesContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.CreateShardingKeyGeneratorContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.CreateShardingTableRuleContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.DataNodesContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.DropShardingAlgorithmContext;
@@ -41,6 +42,7 @@ import 
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatement
 import 
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.DropShardingBroadcastTableRulesContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.DropShardingTableRuleContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.KeyGenerateStrategyContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.KeyGeneratorDefinationContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.ResourcesContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.SchemaNameContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.SetShardingHintDatabaseValueContext;
@@ -63,6 +65,7 @@ import 
org.apache.shardingsphere.sharding.distsql.parser.segment.AutoTableRuleSe
 import 
org.apache.shardingsphere.sharding.distsql.parser.segment.BindingTableRuleSegment;
 import 
org.apache.shardingsphere.sharding.distsql.parser.segment.KeyGenerateSegment;
 import 
org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingAlgorithmSegment;
+import 
org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingKeyGeneratorSegment;
 import 
org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingStrategySegment;
 import 
org.apache.shardingsphere.sharding.distsql.parser.segment.TableRuleSegment;
 import 
org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingAlgorithmStatement;
@@ -73,6 +76,7 @@ import 
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateDefault
 import 
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingAlgorithmStatement;
 import 
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingBindingTableRulesStatement;
 import 
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingBroadcastTableRulesStatement;
+import 
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingKeyGeneratorStatement;
 import 
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingTableRuleStatement;
 import 
org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingAlgorithmStatement;
 import 
org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingBindingTableRulesStatement;
@@ -287,7 +291,7 @@ public final class ShardingDistSQLStatementVisitor extends 
ShardingDistSQLStatem
         if (ctx == null) {
             return null;
         }
-        return new 
ShardingStrategySegment(getIdentifierValue(ctx.strategyType()), 
+        return new 
ShardingStrategySegment(getIdentifierValue(ctx.strategyType()),
                 getIdentifierValue(ctx.shardingColumn().columnName()), 
getIdentifierValue(ctx.shardingAlgorithm().shardingAlgorithmName()));
     }
     
@@ -345,4 +349,13 @@ public final class ShardingDistSQLStatementVisitor extends 
ShardingDistSQLStatem
     public ASTNode visitSchemaName(final SchemaNameContext ctx) {
         return new SchemaSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(), new IdentifierValue(ctx.getText()));
     }
+    
+    @Override
+    public ASTNode visitCreateShardingKeyGenerator(final 
CreateShardingKeyGeneratorContext ctx) {
+        return new 
CreateShardingKeyGeneratorStatement(ctx.keyGeneratorDefination().stream().map(this::buildShardingKeyGeneratorSegment).collect(Collectors.toCollection(LinkedList::new)));
+    }
+    
+    private ShardingKeyGeneratorSegment buildShardingKeyGeneratorSegment(final 
KeyGeneratorDefinationContext ctx) {
+        return new 
ShardingKeyGeneratorSegment(getIdentifierValue(ctx.keyGeneratorName()), 
(AlgorithmSegment) visitAlgorithmDefinition(ctx.algorithmDefinition()));
+    }
 }
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/segment/ShardingKeyGeneratorSegment.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/segment/ShardingKeyGeneratorSegment.java
new file mode 100644
index 0000000..d0264e4
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/segment/ShardingKeyGeneratorSegment.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.distsql.parser.segment;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
+import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
+
+/**
+ * Sharding key generator segment.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class ShardingKeyGeneratorSegment implements ASTNode {
+    
+    private final String keyGeneratorName;
+    
+    private final AlgorithmSegment algorithmSegment;
+}
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/statement/CreateShardingKeyGeneratorStatement.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/statement/CreateShardingKeyGeneratorStatement.java
new file mode 100644
index 0000000..2bc1cbd
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/statement/CreateShardingKeyGeneratorStatement.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.distsql.parser.statement;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.CreateRuleStatement;
+import 
org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingKeyGeneratorSegment;
+
+import java.util.Collection;
+
+/**
+ * Create sharding key generator statement.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class CreateShardingKeyGeneratorStatement extends 
CreateRuleStatement {
+    
+    private final Collection<ShardingKeyGeneratorSegment> keyGeneratorSegments;
+}
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/DuplicateKeyGeneratorException.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/DuplicateKeyGeneratorException.java
new file mode 100644
index 0000000..d2fc0a5
--- /dev/null
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/DuplicateKeyGeneratorException.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.distsql.exception.rule;
+
+import java.util.Collection;
+
+/**
+ * Duplicate key generator exception.
+ */
+public final class DuplicateKeyGeneratorException extends 
RuleDefinitionViolationException {
+    
+    private static final long serialVersionUID = 4965160371403179153L;
+    
+    public DuplicateKeyGeneratorException(final String ruleType, final String 
schemaName, final Collection<String> keyGeneratorNames) {
+        super(1117, String.format("Duplicate %s key generator names `%s` in 
schema `%s`", ruleType, keyGeneratorNames, schemaName));
+    }
+}
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/create/CreateRuleStatementAssert.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/create/CreateRuleStatementAssert.java
index bbffa52..8d2cb99 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/create/CreateRuleStatementAssert.java
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/create/CreateRuleStatementAssert.java
@@ -31,6 +31,7 @@ import 
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateDefault
 import 
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingAlgorithmStatement;
 import 
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingBindingTableRulesStatement;
 import 
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingBroadcastTableRulesStatement;
+import 
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingKeyGeneratorStatement;
 import 
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingTableRuleStatement;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.create.impl.CreateDatabaseDiscoveryRuleStatementAssert;
@@ -44,6 +45,7 @@ import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.create.impl.CreateShardingAlgorithmStatementAssert;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.create.impl.CreateShardingBindingTableRulesStatementAssert;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.create.impl.CreateShardingBroadcastTableRulesStatementAssert;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.create.impl.CreateShardingKeyGeneratorStatementAssert;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.create.impl.CreateShardingTableRuleStatementAssert;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateDataBaseDiscoveryRuleStatementTestCase;
@@ -57,6 +59,7 @@ import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateShardingAlgorithmStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateShardingBindingTableRulesStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateShardingBroadcastTableRulesStatementTestCase;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateShardingKeyGeneratorStatementTestCase;
 
 /**
  * Create RDL Statement assert.
@@ -96,8 +99,10 @@ public final class CreateRuleStatementAssert {
         } else if (actual instanceof CreateDefaultShadowAlgorithmStatement) {
             
CreateDefaultShadowAlgorithmStatementAssert.assertIs(assertContext, 
(CreateDefaultShadowAlgorithmStatement) actual, 
(CreateDefaultShadowAlgorithmStatementTestCase) expected);
         } else if (actual instanceof CreateDefaultSingleTableRuleStatement) {
-            
CreateDefaultSingleTableRuleStatementAssert.assertIs(assertContext, 
(CreateDefaultSingleTableRuleStatement) actual, 
+            
CreateDefaultSingleTableRuleStatementAssert.assertIs(assertContext, 
(CreateDefaultSingleTableRuleStatement) actual,
                     (CreateDefaultSingleTableRuleStatementTestCase) expected);
+        } else if (actual instanceof CreateShardingKeyGeneratorStatement) {
+            CreateShardingKeyGeneratorStatementAssert.assertIs(assertContext, 
(CreateShardingKeyGeneratorStatement) actual, 
(CreateShardingKeyGeneratorStatementTestCase) expected);
         }
     }
 }
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/create/impl/CreateShardingKeyGeneratorStatementAssert.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/create/impl/CreateShardingKeyGeneratorStatementAssert.java
new file mode 100644
index 0000000..6c64f6c
--- /dev/null
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/create/impl/CreateShardingKeyGeneratorStatementAssert.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.create.impl;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingKeyGeneratorSegment;
+import 
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingKeyGeneratorStatement;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.distsql.AlgorithmAssert;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.distsql.rdl.ExpectedShardingKeyGenerator;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateShardingKeyGeneratorStatementTestCase;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Create sharding key generator statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class CreateShardingKeyGeneratorStatementAssert {
+    
+    /**
+     * Assert create sharding key generator statement is correct with expected 
parser result.
+     *
+     * @param assertContext assert context
+     * @param actual actual create sharding key generator statement
+     * @param expected expected create sharding key generator statement test 
case
+     */
+    public static void assertIs(final SQLCaseAssertContext assertContext, 
final CreateShardingKeyGeneratorStatement actual, final 
CreateShardingKeyGeneratorStatementTestCase expected) {
+        if (null == expected) {
+            assertNull(assertContext.getText("Actual statement should not 
exist."), actual);
+        } else {
+            assertNotNull(assertContext.getText("Actual statement should 
exist."), actual);
+            assertShardingKeyGenerator(assertContext, 
actual.getKeyGeneratorSegments(), expected.getShardingKeyGenerators());
+        }
+    }
+    
+    private static void assertShardingKeyGenerator(final SQLCaseAssertContext 
assertContext, final Collection<ShardingKeyGeneratorSegment> actual, final 
List<ExpectedShardingKeyGenerator> expected) {
+        if (null == expected) {
+            assertNull(assertContext.getText("Actual sharding key generator 
should not exist."), actual);
+        } else {
+            assertNotNull(assertContext.getText("Actual sharding key generator 
should exist."), actual);
+            final Map<String, ShardingKeyGeneratorSegment> actualMap = 
actual.stream().collect(Collectors.toMap(ShardingKeyGeneratorSegment::getKeyGeneratorName,
 each -> each));
+            for (ExpectedShardingKeyGenerator each : expected) {
+                ShardingKeyGeneratorSegment actualAlgorithm = 
actualMap.get(each.getKeyGeneratorName());
+                assertNotNull(assertContext.getText("Actual sharding key 
generator should exist."), actualAlgorithm);
+                assertThat(actualAlgorithm.getKeyGeneratorName(), 
is(each.getKeyGeneratorName()));
+                AlgorithmAssert.assertIs(assertContext, 
actualAlgorithm.getAlgorithmSegment(), each.getAlgorithmSegment());
+            }
+        }
+    }
+}
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
index acc3360..3c05de7 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
@@ -178,6 +178,7 @@ import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateShardingAutoTableRuleStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateShardingBindingTableRulesStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateShardingBroadcastTableRulesStatementTestCase;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateShardingKeyGeneratorStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateShardingTableRuleStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropDataBaseDiscoveryRuleStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropDefaultSingleTableRuleStatementTestCase;
@@ -756,6 +757,9 @@ public final class SQLParserTestCases {
     @XmlElement(name = "create-sharding-algorithm")
     private final List<CreateShardingAlgorithmStatementTestCase> 
createShardingAlgorithmStatementTestCases = new LinkedList<>();
     
+    @XmlElement(name = "create-sharding-key-generator")
+    private final List<CreateShardingKeyGeneratorStatementTestCase> 
createShardingKeyGeneratorStatementTestCases = new LinkedList<>();
+    
     @XmlElement(name = "create-default-sharding-strategy")
     private final List<CreateDefaultShardingStrategyStatementTestCase> 
createDefaultShardingStrategyStatementTestCases = new LinkedList<>();
     
@@ -1007,6 +1011,7 @@ public final class SQLParserTestCases {
         putAll(optimizeTableStatementTestCases, result);
         putAll(repairTableStatementTestCases, result);
         putAll(createShardingAlgorithmStatementTestCases, result);
+        putAll(createShardingKeyGeneratorStatementTestCases, result);
         putAll(createDefaultShardingStrategyStatementTestCases, result);
         putAll(createShardingTableRuleTestCases, result);
         putAll(alterShardingTableRuleTestCases, result);
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/distsql/rdl/ExpectedShardingKeyGenerator.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/distsql/rdl/ExpectedShardingKeyGenerator.java
new file mode 100644
index 0000000..6163172
--- /dev/null
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/distsql/rdl/ExpectedShardingKeyGenerator.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.distsql.rdl;
+
+import lombok.Getter;
+import lombok.Setter;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.AbstractExpectedIdentifierSQLSegment;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.distsql.ExpectedAlgorithm;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ * Expected sharding key generator.
+ */
+@Getter
+@Setter
+public final class ExpectedShardingKeyGenerator extends 
AbstractExpectedIdentifierSQLSegment {
+    
+    @XmlAttribute(name = "key-generator-name")
+    private String keyGeneratorName;
+    
+    @XmlElement(name = "algorithm")
+    private ExpectedAlgorithm algorithmSegment;
+}
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/create/CreateShardingKeyGeneratorStatementTestCase.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/create/CreateShardingKeyGeneratorStatementTestCase.java
new file mode 100644
index 0000000..ca857ca
--- /dev/null
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/create/CreateShardingKeyGeneratorStatementTestCase.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create;
+
+import lombok.Getter;
+import lombok.Setter;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.distsql.rdl.ExpectedShardingKeyGenerator;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+
+import javax.xml.bind.annotation.XmlElement;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Create sharding key generator statement test case.
+ */
+@Getter
+@Setter
+public final class CreateShardingKeyGeneratorStatementTestCase extends 
SQLParserTestCase {
+    
+    @XmlElement(name = "shardingKeyGenerator")
+    private final List<ExpectedShardingKeyGenerator> shardingKeyGenerators = 
new LinkedList<>();
+}
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/create.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/create.xml
index 693d64c..47b4654 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/create.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/create.xml
@@ -242,7 +242,7 @@
     
     <create-encrypt-rule 
sql-case-id="create-encrypt-rule-with-assisted-query-column">
         <rule name="t_encrypt">
-            <column name="user_id" plain-column="user_plain" 
cipher-column="user_cipher" assisted-query-column = "assisted_column">
+            <column name="user_id" plain-column="user_plain" 
cipher-column="user_cipher" assisted-query-column="assisted_column">
                 <encryptor algorithm-name="AES">
                     <properties>
                         <property key="aes-key-value" value="123456abc"/>
@@ -269,7 +269,7 @@
     
     <create-shadow-rule sql-case-id="create-shadow-rule">
         <rule name="rule" rule-name="shadow_rule" source="demo_ds" 
shadow="demo_ds_shadow">
-            <table-rule  table-name="t_order">
+            <table-rule table-name="t_order">
                 <shadow-algorithm 
algorithm-id="shadow_rule_t_order_column_regex_match">
                     <algorithm algorithm-name="COLUMN_REGEX_MATCH">
                         <properties>
@@ -293,7 +293,7 @@
 
     <create-shadow-rule sql-case-id="create-shadow-rule-with-quota">
         <rule name="rule" rule-name="shadow_rule" source="demo_ds" 
shadow="demo_ds_shadow">
-            <table-rule  table-name="t_order">
+            <table-rule table-name="t_order">
                 <shadow-algorithm 
algorithm-id="shadow_rule_t_order_column_regex_match">
                     <algorithm algorithm-name="COLUMN_REGEX_MATCH">
                         <properties>
@@ -316,7 +316,7 @@
     </create-shadow-rule>
     
     <create-sharding-algorithm sql-case-id="create-sharding-algorithm">
-        <shardingAlgorithm  sharding-algorithm-name="algorithm_name">
+        <shardingAlgorithm sharding-algorithm-name="algorithm_name">
             <algorithm algorithm-name="hash_mod">
                 <properties>
                     <property key="algorithm-expression" 
value="t_order_${order_id % 2}"/>
@@ -325,7 +325,7 @@
         </shardingAlgorithm>
     </create-sharding-algorithm>
 
-    <create-default-shadow-algorithm 
sql-case-id="create-default-shadow-algorithm" algorithm="simple_hint_algorithm" 
/>
+    <create-default-shadow-algorithm 
sql-case-id="create-default-shadow-algorithm" 
algorithm="simple_hint_algorithm"/>
     
     <create-default-sharding-strategy 
sql-case-id="create-default-sharding-strategy">
         <strategy default-type="table" strategy-type="standard" 
sharding-column="order_id" sharding-algorithm-name="algorithms_name">
@@ -342,6 +342,16 @@
             </algorithm>
         </shadow-algorithm>
     </create-shadow-algorithm>
-    
-    <create-default-single-table sql-case-id="create-default-single-table" 
default-data-source="ds_0" />
+
+    <create-default-single-table sql-case-id="create-default-single-table" 
default-data-source="ds_0"/>
+
+    <create-sharding-key-generator sql-case-id="create-sharding-key-generator">
+        <shardingKeyGenerator key-generator-name="uuid_key_generator">
+            <algorithm algorithm-name="uuid">
+                <properties>
+                    <property key="worker-id" value="123"/>
+                </properties>
+            </algorithm>
+        </shardingKeyGenerator>
+    </create-sharding-key-generator>
 </sql-parser-test-cases>
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/create.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/create.xml
index dfa515b..36165aa 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/create.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/create.xml
@@ -52,4 +52,5 @@
     <distsql-case id="create-encrypt-rule-with-quota" value="CREATE ENCRYPT 
RULE `encrypt` (RESOURCE=ds_1, 
COLUMNS((NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,TYPE(NAME=AES,PROPERTIES('aes-key-value'='123456abc'))),
 (NAME=order_id, CIPHER =order_cipher,TYPE(NAME=MD5))))" />
     <distsql-case id="create-encrypt-rule-with-query-with-cipher-column" 
value="CREATE ENCRYPT RULE `encrypt` (RESOURCE=ds_1, 
COLUMNS((NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,TYPE(NAME=AES,PROPERTIES('aes-key-value'='123456abc')))),QUERY_WITH_CIPHER_COLUMN=false)"
 />
     <distsql-case id="create-shadow-rule-with-quota" value="CREATE SHADOW RULE 
`shadow_rule`(SOURCE=demo_ds,SHADOW=demo_ds_shadow,t_order((TYPE(NAME=COLUMN_REGEX_MATCH,PROPERTIES('operation'='insert','column'='user_id','regex'='[1]'))),(simple_note_algorithm,TYPE(NAME=SIMPLE_NOTE,PROPERTIES('shadow'='true',foo='bar')))))"
 />
+    <distsql-case id="create-sharding-key-generator" value="CREATE SHARDING 
KEY GENERATOR uuid_key_generator(TYPE(NAME=uuid,PROPERTIES('worker-id'=123)))" 
/>
 </sql-cases>

Reply via email to