Skip to content

Commit

Permalink
Fix sonar issue on ShardingIndexReviser
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Sep 23, 2023
1 parent 9c66e4c commit 4a4eeab
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,13 +35,13 @@ public final class ShardingIndexReviser implements IndexReviser<ShardingRule> {

@Override
public Optional<IndexMetaData> 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) {
Expand Down

0 comments on commit 4a4eeab

Please sign in to comment.