yx9o commented on code in PR #23086:
URL: https://github.com/apache/shardingsphere/pull/23086#discussion_r1056954344
##########
features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateShadowRuleStatementUpdater.java:
##########
@@ -66,17 +68,23 @@ private void updateTables(final Map<String,
ShadowTableConfiguration> currentTab
public void checkSQLStatement(final ShardingSphereDatabase database, final
CreateShadowRuleStatement sqlStatement, final ShadowRuleConfiguration
currentRuleConfig) {
String databaseName = database.getName();
Collection<ShadowRuleSegment> rules = sqlStatement.getRules();
- checkRuleNames(databaseName, rules, currentRuleConfig);
+ checkRuleNames(databaseName, sqlStatement, currentRuleConfig);
checkResources(database, rules);
- checkAlgorithms(databaseName, sqlStatement.getRules());
- checkAlgorithmType(sqlStatement);
+ checkAlgorithms(databaseName, rules);
+ checkAlgorithmType(rules);
}
- private void checkRuleNames(final String databaseName, final
Collection<ShadowRuleSegment> rules, final ShadowRuleConfiguration
currentRuleConfig) {
- Collection<String> requireRuleNames =
ShadowRuleStatementSupporter.getRuleNames(rules);
+ private void checkRuleNames(final String databaseName, final
CreateShadowRuleStatement sqlStatement, final ShadowRuleConfiguration
currentRuleConfig) {
+ Collection<String> requireRuleNames =
ShadowRuleStatementSupporter.getRuleNames(sqlStatement.getRules());
ShadowRuleStatementChecker.checkAnyDuplicate(requireRuleNames,
duplicated -> new DuplicateRuleException(SHADOW, databaseName, duplicated));
- Collection<String> currentRuleName =
ShadowRuleStatementSupporter.getRuleNames(currentRuleConfig);
- ShadowRuleStatementChecker.checkAnyDuplicate(requireRuleNames,
currentRuleName, identical -> new DuplicateRuleException(SHADOW, databaseName,
identical));
+ identicalRuleNames = getIdentical(requireRuleNames,
ShadowRuleStatementSupporter.getRuleNames(currentRuleConfig));
+ if (!sqlStatement.isIfNotExists()) {
+
ShardingSpherePreconditions.checkState(identicalRuleNames.isEmpty(), () -> new
DuplicateRuleException(SHADOW, databaseName, identicalRuleNames));
+ }
+ }
+
+ private static Collection<String> getIdentical(final Collection<String>
require, final Collection<String> current) {
Review Comment:
> Hi @yx9o , can this method be replaced with `retainAll`, do they mean the
same?
ok.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]