This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 9fad8576282 Refactor ShardingSphereStatisticsCollector (#37028)
9fad8576282 is described below
commit 9fad85762829e1f478974f2d86d8272ef6dc91eb
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Nov 6 19:55:30 2025 +0800
Refactor ShardingSphereStatisticsCollector (#37028)
---
.../infra/metadata/statistics/RowStatistics.java | 13 +++++++------
.../shardingsphere/ShardingSphereStatisticsCollector.java | 15 ++-------------
2 files changed, 9 insertions(+), 19 deletions(-)
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/RowStatistics.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/RowStatistics.java
index d879a8a9297..baf79db9a31 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/RowStatistics.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/RowStatistics.java
@@ -25,6 +25,8 @@ import lombok.SneakyThrows;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Collection;
import java.util.List;
/**
@@ -38,7 +40,7 @@ public final class RowStatistics {
@EqualsAndHashCode.Include
private final String uniqueKey;
- private final List<Object> rows;
+ private final Collection<Object> rows;
public RowStatistics(final List<Object> rows) {
uniqueKey = generateUniqueKey(rows);
@@ -48,16 +50,15 @@ public final class RowStatistics {
private String generateUniqueKey(final List<Object> rows) {
StringBuilder uniqueKeyText = new StringBuilder();
for (Object each : rows) {
- if (null == each) {
- uniqueKeyText.append('|');
- } else {
- uniqueKeyText.append(each).append('|');
+ if (null != each) {
+ uniqueKeyText.append(each);
}
+ uniqueKeyText.append('|');
}
return useMd5GenerateUniqueKey(uniqueKeyText);
}
- @SneakyThrows
+ @SneakyThrows(NoSuchAlgorithmException.class)
private String useMd5GenerateUniqueKey(final StringBuilder uniqueKeyText) {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(StandardCharsets.UTF_8.encode(uniqueKeyText.toString()));
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/shardingsphere/ShardingSphereStatisticsCollector.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/shardingsphere/ShardingSphereStatisticsCollector.java
index 403aef08459..49b5b689b70 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/shardingsphere/ShardingSphereStatisticsCollector.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/shardingsphere/ShardingSphereStatisticsCollector.java
@@ -27,7 +27,6 @@ import
org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Optional;
/**
@@ -56,17 +55,7 @@ public final class ShardingSphereStatisticsCollector
implements DialectDatabaseS
@Override
public boolean isStatisticsTables(final Map<String, Collection<String>>
schemaTables) {
- if (schemaTables.isEmpty()) {
- return false;
- }
- for (Entry<String, Collection<String>> entry :
schemaTables.entrySet()) {
- if (!STATISTICS_SCHEMA_TABLES.containsKey(entry.getKey())) {
- return false;
- }
- if
(!STATISTICS_SCHEMA_TABLES.get(entry.getKey()).containsAll(entry.getValue())) {
- return false;
- }
- }
- return true;
+ return !schemaTables.isEmpty() && schemaTables.entrySet().stream()
+ .noneMatch(entry ->
!STATISTICS_SCHEMA_TABLES.containsKey(entry.getKey()) ||
!STATISTICS_SCHEMA_TABLES.get(entry.getKey()).containsAll(entry.getValue()));
}
}