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 1f51912 add alter sharding key generator DistSQL parser. (#14051)
1f51912 is described below
commit 1f5191223976bc73da226f087fb955035b4281a4
Author: Zonglei Dong <[email protected]>
AuthorDate: Mon Dec 13 13:25:38 2021 +0800
add alter sharding key generator DistSQL parser. (#14051)
* Add alter sharding key generator DistSQL parser.
* Add alter sharding key generator DistSQL parser test case.
* fixes alter sharding key generator DistSQL parser updater code logic.
* fixes checkstyle problem, remove useless import.
* Fix code merge conflict.
* Fix code merge conflict.
---
.../AlterShardingKeyGeneratorStatementUpdater.java | 99 ++++++++++++++++++++++
...here.infra.distsql.update.RuleDefinitionUpdater | 1 +
...erShardingKeyGeneratorStatementUpdaterTest.java | 86 +++++++++++++++++++
.../main/antlr4/imports/sharding/RDLStatement.g4 | 20 +++--
.../parser/autogen/ShardingDistSQLStatement.g4 | 1 +
.../core/ShardingDistSQLStatementVisitor.java | 7 ++
.../AlterShardingKeyGeneratorStatement.java | 35 ++++++++
.../jaxb/cases/domain/SQLParserTestCases.java | 5 ++
...AlterShardingKeyGeneratorStatementTestCase.java | 38 +++++++++
.../src/main/resources/case/rdl/alter.xml | 10 +++
.../src/main/resources/sql/supported/rdl/alter.xml | 1 +
11 files changed, 295 insertions(+), 8 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/AlterShardingKeyGeneratorStatementUpdater.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingKeyGeneratorStatementUpdater.java
new file mode 100644
index 0000000..9210a8c
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingKeyGeneratorStatementUpdater.java
@@ -0,0 +1,99 @@
+/*
+ * 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.DuplicateRuleException;
+import
org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException;
+import
org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException;
+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.AlterShardingKeyGeneratorStatement;
+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.stream.Collectors;
+
+/**
+ * Alter sharding key generator statement updater.
+ */
+public final class AlterShardingKeyGeneratorStatementUpdater implements
RuleDefinitionCreateUpdater<AlterShardingKeyGeneratorStatement,
ShardingRuleConfiguration> {
+
+ @Override
+ public void checkSQLStatement(final ShardingSphereMetaData
shardingSphereMetaData, final AlterShardingKeyGeneratorStatement sqlStatement,
+ final ShardingRuleConfiguration
currentRuleConfig) throws DistSQLException {
+ String schemaName = shardingSphereMetaData.getName();
+ LinkedList<String> requireNames =
sqlStatement.getKeyGeneratorSegments().stream().map(ShardingKeyGeneratorSegment::getKeyGeneratorName).collect(Collectors.toCollection(LinkedList::new));
+ checkDuplicate(schemaName, requireNames);
+ checkExist(requireNames, currentRuleConfig);
+ checkAlgorithmType(sqlStatement);
+ }
+
+ private void checkDuplicate(final String schemaName, final
Collection<String> requireNames) throws DistSQLException {
+ Set<String> duplicateRequire =
requireNames.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(), new
DuplicateRuleException("sharding", schemaName, duplicateRequire));
+ }
+
+ private void checkExist(final Collection<String> requireNames, final
ShardingRuleConfiguration currentRuleConfig) throws DistSQLException {
+ LinkedList<String> notExistAlgorithms =
requireNames.stream().filter(each ->
!currentRuleConfig.getKeyGenerators().containsKey(each)).collect(Collectors.toCollection(LinkedList::new));
+ DistSQLException.predictionThrow(notExistAlgorithms.isEmpty(), new
RequiredAlgorithmMissedException("sharding", notExistAlgorithms));
+ }
+
+ private void checkAlgorithmType(final AlterShardingKeyGeneratorStatement
sqlStatement) throws DistSQLException {
+ LinkedList<String> requireNames =
sqlStatement.getKeyGeneratorSegments().stream()
+
.map(ShardingKeyGeneratorSegment::getAlgorithmSegment).map(AlgorithmSegment::getName).collect(Collectors.toCollection(LinkedList::new));
+ Collection<String> invalidAlgorithmNames = requireNames.stream()
+ .filter(each ->
!TypedSPIRegistry.findRegisteredService(KeyGenerateAlgorithm.class, each, new
Properties()).isPresent()).collect(Collectors.toList());
+ DistSQLException.predictionThrow(invalidAlgorithmNames.isEmpty(), new
InvalidAlgorithmConfigurationException("sharding", invalidAlgorithmNames));
+ }
+
+ @Override
+ public ShardingRuleConfiguration buildToBeCreatedRuleConfiguration(final
AlterShardingKeyGeneratorStatement sqlStatement) {
+ ShardingRuleConfiguration result = new ShardingRuleConfiguration();
+ Map<String, ShardingSphereAlgorithmConfiguration>
algorithmConfigurationMap = sqlStatement.getKeyGeneratorSegments().stream()
+
.collect(Collectors.toMap(ShardingKeyGeneratorSegment::getKeyGeneratorName,
each ->
ShardingTableRuleStatementConverter.createAlgorithmConfiguration(each.getAlgorithmSegment())));
+ result.setKeyGenerators(algorithmConfigurationMap);
+ return result;
+ }
+
+ @Override
+ public void updateCurrentRuleConfiguration(final ShardingRuleConfiguration
currentRuleConfig, final ShardingRuleConfiguration toBeCreatedRuleConfig) {
+
currentRuleConfig.getKeyGenerators().putAll(toBeCreatedRuleConfig.getShardingAlgorithms());
+ }
+
+ @Override
+ public Class<ShardingRuleConfiguration> getRuleConfigurationClass() {
+ return ShardingRuleConfiguration.class;
+ }
+
+ @Override
+ public String getType() {
+ return AlterShardingKeyGeneratorStatement.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 6cf7865..0a912e4 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
@@ -29,3 +29,4 @@
org.apache.shardingsphere.sharding.distsql.handler.update.DropShardingBroadcastT
org.apache.shardingsphere.sharding.distsql.handler.update.CreateDefaultShardingStrategyStatementUpdater
org.apache.shardingsphere.sharding.distsql.handler.update.AlterShardingAlgorithmStatementUpdater
org.apache.shardingsphere.sharding.distsql.handler.update.CreateShardingKeyGeneratorStatementUpdater
+org.apache.shardingsphere.sharding.distsql.handler.update.AlterShardingKeyGeneratorStatementUpdater
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingKeyGeneratorStatementUpdaterTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingKeyGeneratorStatementUpdaterTest.java
new file mode 100644
index 0000000..7fe3943
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingKeyGeneratorStatementUpdaterTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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.DuplicateRuleException;
+import
org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException;
+import
org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import
org.apache.shardingsphere.sharding.distsql.handler.update.AlterShardingKeyGeneratorStatementUpdater;
+import
org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingKeyGeneratorSegment;
+import
org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingKeyGeneratorStatement;
+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 AlterShardingKeyGeneratorStatementUpdaterTest {
+
+ @Mock
+ private ShardingSphereMetaData shardingSphereMetaData;
+
+ private final AlterShardingKeyGeneratorStatementUpdater updater = new
AlterShardingKeyGeneratorStatementUpdater();
+
+ @Before
+ public void before() {
+ when(shardingSphereMetaData.getName()).thenReturn("test");
+ }
+
+ @Test(expected = DuplicateRuleException.class)
+ public void assertExecuteWithDuplicate() throws DistSQLException {
+ Properties properties = new Properties();
+ properties.put("inputKey", "inputValue");
+ ShardingKeyGeneratorSegment keyGeneratorSegment = new
ShardingKeyGeneratorSegment("inputAlgorithmName", new
AlgorithmSegment("inputAlgorithmName", properties));
+ updater.checkSQLStatement(shardingSphereMetaData,
createSQLStatement(keyGeneratorSegment, keyGeneratorSegment), null);
+ }
+
+ @Test(expected = RequiredAlgorithmMissedException.class)
+ public void assertExecuteWithNotExist() throws DistSQLException {
+ Properties properties = new Properties();
+ properties.put("inputKey", "inputValue");
+ ShardingKeyGeneratorSegment keyGeneratorSegment = new
ShardingKeyGeneratorSegment("notExistAlgorithmName", new
AlgorithmSegment("inputAlgorithmName", properties));
+ ShardingRuleConfiguration shardingRuleConfiguration = new
ShardingRuleConfiguration();
+
shardingRuleConfiguration.getShardingAlgorithms().put("existAlgorithmName", new
ShardingSphereAlgorithmConfiguration("hash_mod", properties));
+ updater.checkSQLStatement(shardingSphereMetaData,
createSQLStatement(keyGeneratorSegment), shardingRuleConfiguration);
+ }
+
+ @Test(expected = InvalidAlgorithmConfigurationException.class)
+ public void assertExecuteWithInvalidAlgorithm() throws DistSQLException {
+ Properties properties = new Properties();
+ properties.put("inputKey", "inputValue");
+ ShardingKeyGeneratorSegment keyGeneratorSegment = new
ShardingKeyGeneratorSegment("existAlgorithmName", new
AlgorithmSegment("inputAlgorithmName", properties));
+ ShardingRuleConfiguration shardingRuleConfiguration = new
ShardingRuleConfiguration();
+ shardingRuleConfiguration.getKeyGenerators().put("existAlgorithmName",
new ShardingSphereAlgorithmConfiguration("InvalidAlgorithm", properties));
+ updater.checkSQLStatement(shardingSphereMetaData,
createSQLStatement(keyGeneratorSegment), shardingRuleConfiguration);
+ }
+
+ private AlterShardingKeyGeneratorStatement createSQLStatement(final
ShardingKeyGeneratorSegment... ruleSegments) {
+ return new
AlterShardingKeyGeneratorStatement(Arrays.asList(ruleSegments));
+ }
+}
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 b25fef2..0cce750 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
@@ -59,6 +59,10 @@ alterShardingAlgorithm
: ALTER SHARDING ALGORITHM shardingAlgorithmDefinition (COMMA
shardingAlgorithmDefinition)*
;
+alterShardingKeyGenerator
+ : ALTER SHARDING KEY GENERATOR keyGeneratorDefination (COMMA
keyGeneratorDefination)*
+ ;
+
dropShardingTableRule
: DROP SHARDING TABLE RULE tableName (COMMA tableName)*
;
@@ -87,6 +91,14 @@ shardingTableRule
: tableName LP dataNodes (COMMA databaseStrategy)? (COMMA tableStrategy)?
(COMMA keyGenerateStrategy)? RP
;
+keyGeneratorDefination
+ : keyGeneratorName LP algorithmDefinition RP
+ ;
+
+keyGeneratorName
+ : IDENTIFIER
+ ;
+
resources
: RESOURCES LP resource (COMMA resource)* RP
;
@@ -166,11 +178,3 @@ 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 854df10..458b212 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
@@ -44,5 +44,6 @@ execute
| alterShardingAlgorithm
| showShardingTableNodes
| createShardingKeyGenerator
+ | alterShardingKeyGenerator
) 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 43068c4..3bbeaaf 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
@@ -27,6 +27,7 @@ import
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatement
import
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.AlterShardingAlgorithmContext;
import
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.AlterShardingBindingTableRulesContext;
import
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.AlterShardingBroadcastTableRulesContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.AlterShardingKeyGeneratorContext;
import
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.AlterShardingTableRuleContext;
import
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.BindTableRulesDefinitionContext;
import
org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.ClearShardingHintContext;
@@ -71,6 +72,7 @@ import
org.apache.shardingsphere.sharding.distsql.parser.segment.TableRuleSegmen
import
org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingAlgorithmStatement;
import
org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingBindingTableRulesStatement;
import
org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingBroadcastTableRulesStatement;
+import
org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingKeyGeneratorStatement;
import
org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingTableRuleStatement;
import
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateDefaultShardingStrategyStatement;
import
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingAlgorithmStatement;
@@ -355,6 +357,11 @@ public final class ShardingDistSQLStatementVisitor extends
ShardingDistSQLStatem
return new
CreateShardingKeyGeneratorStatement(ctx.keyGeneratorDefination().stream().map(this::buildShardingKeyGeneratorSegment).collect(Collectors.toCollection(LinkedList::new)));
}
+ @Override
+ public ASTNode visitAlterShardingKeyGenerator(final
AlterShardingKeyGeneratorContext ctx) {
+ return new
AlterShardingKeyGeneratorStatement(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/statement/AlterShardingKeyGeneratorStatement.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/statement/AlterShardingKeyGeneratorStatement.java
new file mode 100644
index 0000000..f4f7bac
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/statement/AlterShardingKeyGeneratorStatement.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.alter.AlterRuleStatement;
+import
org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingKeyGeneratorSegment;
+
+import java.util.Collection;
+
+/**
+ * Alter sharding key generator statement.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class AlterShardingKeyGeneratorStatement extends
AlterRuleStatement {
+
+ private final Collection<ShardingKeyGeneratorSegment> keyGeneratorSegments;
+}
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 3c05de7..6cd0894 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
@@ -164,6 +164,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.alter.AlterShardingAutoTableRuleStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.AlterShardingBindingTableRulesStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.AlterShardingBroadcastTableRulesStatementTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.AlterShardingKeyGeneratorStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.AlterShardingTableRuleStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.AddResourceStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateDataBaseDiscoveryRuleStatementTestCase;
@@ -778,6 +779,9 @@ public final class SQLParserTestCases {
@XmlElement(name = "alter-sharding-algorithm")
private final List<AlterShardingAlgorithmStatementTestCase>
alterShardingAlgorithmStatementTestCases = new LinkedList<>();
+ @XmlElement(name = "alter-sharding-key-generator")
+ private final List<AlterShardingKeyGeneratorStatementTestCase>
alterShardingKeyGeneratorStatementTestCases = new LinkedList<>();
+
@XmlElement(name = "reset")
private final List<ResetStatementTestCase> resetStatementTestCases = new
LinkedList<>();
@@ -1021,6 +1025,7 @@ public final class SQLParserTestCases {
putAll(showReplicaStatusStatementTestCases, result);
putAll(showSlaveStatusStatementTestCases, result);
putAll(alterShardingAlgorithmStatementTestCases, result);
+ putAll(alterShardingKeyGeneratorStatementTestCases, result);
putAll(killStatementTestCases, result);
putAll(createDefaultShadowAlgorithmStatementTestCases, result);
putAll(cacheIndexStatementTestCases, result);
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/alter/AlterShardingKeyGeneratorStatementTestCase.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/alter/AlterShardingKeyGeneratorStatementTestCase.java
new file mode 100644
index 0000000..54ffd7c
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/alter/AlterShardingKeyGeneratorStatementTestCase.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.alter;
+
+import lombok.Getter;
+import lombok.Setter;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.distsql.rdl.ExpectedShardingAlgorithm;
+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;
+
+/**
+ * Alter sharding key generator statement test case.
+ */
+@Getter
+@Setter
+public final class AlterShardingKeyGeneratorStatementTestCase extends
SQLParserTestCase {
+
+ @XmlElement(name = "keyGenerator")
+ private final List<ExpectedShardingAlgorithm> shardingAlgorithms = new
LinkedList<>();
+}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/alter.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/alter.xml
index 0edc466..005bc04 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/alter.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/alter.xml
@@ -240,5 +240,15 @@
</shardingAlgorithm>
</alter-sharding-algorithm>
+ <alter-sharding-key-generator sql-case-id="alter-sharding-key-generator">
+ <keyGenerator key-generator-name="uuid_key_generator">
+ <algorithm algorithm-name="inline">
+ <properties>
+ <property key="worker-id" value="123"/>
+ </properties>
+ </algorithm>
+ </keyGenerator>
+ </alter-sharding-key-generator>
+
<alter-default-single-table sql-case-id="alter-default-single-table"
default-data-source="ds_0" />
</sql-parser-test-cases>
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/alter.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/alter.xml
index f10505f..3d01aae 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/alter.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/alter.xml
@@ -40,4 +40,5 @@
<distsql-case id="alter-sharding-table-rule" value="ALTER SHARDING TABLE
RULE t_order (DATANODES('ms_group_${0..1}'),DATABASE_STRATEGY( TYPE =
`standard`,sharding_column = order_id,sharding_algorithm =
database_inline),TABLE_STRATEGY(TYPE = `standard`,sharding_column =
user_id,sharding_algorithm =
table_inline),GENERATED_KEY(COLUMN=another_id,TYPE(NAME=snowflake,PROPERTIES('worker-id'=123))))"
/>"
<distsql-case id="alter-sharding-algorithm" value="ALTER SHARDING
ALGORITHM algorithm_name(TYPE(NAME=inline,PROPERTIES('algorithm-expression' =
't_order_${order_id % 2}')))" />
<distsql-case id="alter-default-single-table" value="ALTER DEFAULT SINGLE
TABLE RULE RESOURCE = ds_0" />
+ <distsql-case id="alter-sharding-key-generator" value="ALTER SHARDING KEY
GENERATOR uuid_key_generator(TYPE(NAME=uuid,PROPERTIES('worker-id' = '123')))"
/>
</sql-cases>