From 4a4eeab0592b6aae91e73a00a12d2fa9f33664d0 Mon Sep 17 00:00:00 2001 From: zhangliang Date: Sun, 24 Sep 2023 00:17:12 +0800 Subject: [PATCH] Fix sonar issue on ShardingIndexReviser --- .../reviser/index/ShardingIndexReviser.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/reviser/index/ShardingIndexReviser.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/reviser/index/ShardingIndexReviser.java index 00c6b9e86b317..417c002e6f94e 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/reviser/index/ShardingIndexReviser.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/reviser/index/ShardingIndexReviser.java @@ -19,7 +19,6 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.database.core.metadata.data.model.IndexMetaData; -import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.metadata.database.schema.reviser.index.IndexReviser; import org.apache.shardingsphere.sharding.rule.ShardingRule; import org.apache.shardingsphere.sharding.rule.TableRule; @@ -36,13 +35,13 @@ public final class ShardingIndexReviser implements IndexReviser { @Override public Optional revise(final String tableName, final IndexMetaData originalMetaData, final ShardingRule rule) { - for (DataNode each : tableRule.getActualDataNodes()) { - IndexMetaData result = new IndexMetaData(getLogicIndex(originalMetaData.getName(), each.getTableName())); - result.getColumns().addAll(originalMetaData.getColumns()); - result.setUnique(originalMetaData.isUnique()); - return Optional.of(result); + if (tableRule.getActualDataNodes().isEmpty()) { + return Optional.empty(); } - return Optional.empty(); + IndexMetaData result = new IndexMetaData(getLogicIndex(originalMetaData.getName(), tableRule.getActualDataNodes().iterator().next().getTableName())); + result.getColumns().addAll(originalMetaData.getColumns()); + result.setUnique(originalMetaData.isUnique()); + return Optional.of(result); } private String getLogicIndex(final String actualIndexName, final String actualTableName) {