This is an automated email from the ASF dual-hosted git repository.

zhaojinchao 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 d248bae480d Refactor ShardingSphereStatisticsCollector (#30248)
d248bae480d is described below

commit d248bae480db44ce48cef167d87d2855d6c2b832
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Feb 22 23:18:06 2024 +0800

    Refactor ShardingSphereStatisticsCollector (#30248)
    
    * Refactor YamlBroadcastRuleConfigurationSwapper
    
    * Refactor ShardingSphereStatisticsCollector
---
 .../sharding/metadata/data/ShardingStatisticsTableCollector.java | 9 ++++-----
 .../statistics/collector/ShardingSphereStatisticsCollector.java  | 6 +++---
 .../statistics/collector/tables/PgClassTableCollector.java       | 7 +++----
 .../statistics/collector/tables/PgNamespaceTableCollector.java   | 5 ++---
 .../core/job/statistics/collect/StatisticsCollectorFixture.java  | 3 +--
 5 files changed, 13 insertions(+), 17 deletions(-)

diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java
index f10a97b238c..802f0129b20 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java
@@ -48,15 +48,14 @@ public final class ShardingStatisticsTableCollector 
implements ShardingSphereSta
     private static final String SHARDING_TABLE_STATISTICS = 
"sharding_table_statistics";
     
     @Override
-    public Optional<ShardingSphereTableData> collect(final String 
databaseName, final ShardingSphereTable table,
-                                                     final Map<String, 
ShardingSphereDatabase> shardingSphereDatabases) throws SQLException {
+    public Optional<ShardingSphereTableData> collect(final String 
databaseName, final ShardingSphereTable table, final Map<String, 
ShardingSphereDatabase> databases) throws SQLException {
         ShardingSphereTableData result = new 
ShardingSphereTableData(SHARDING_TABLE_STATISTICS);
-        DatabaseType protocolType = 
shardingSphereDatabases.values().iterator().next().getProtocolType();
+        DatabaseType protocolType = 
databases.values().iterator().next().getProtocolType();
         DialectDatabaseMetaData dialectDatabaseMetaData = new 
DatabaseTypeRegistry(protocolType).getDialectDatabaseMetaData();
         if (dialectDatabaseMetaData.getDefaultSchema().isPresent()) {
-            collectFromDatabase(shardingSphereDatabases.get(databaseName), 
result);
+            collectFromDatabase(databases.get(databaseName), result);
         } else {
-            for (ShardingSphereDatabase each : 
shardingSphereDatabases.values()) {
+            for (ShardingSphereDatabase each : databases.values()) {
                 collectFromDatabase(each, result);
             }
         }
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/ShardingSphereStatisticsCollector.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/ShardingSphereStatisticsCollector.java
index e88484490c9..2e4a1f9dda9 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/ShardingSphereStatisticsCollector.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/ShardingSphereStatisticsCollector.java
@@ -38,9 +38,9 @@ public interface ShardingSphereStatisticsCollector extends 
TypedSPI {
      *
      * @param databaseName database name
      * @param table table
-     * @param shardingSphereDatabases ShardingSphere databases
+     * @param databases databases
      * @return ShardingSphere table data
-     * @throws SQLException sql exception
+     * @throws SQLException SQL exception
      */
-    Optional<ShardingSphereTableData> collect(String databaseName, 
ShardingSphereTable table, Map<String, ShardingSphereDatabase> 
shardingSphereDatabases) throws SQLException;
+    Optional<ShardingSphereTableData> collect(String databaseName, 
ShardingSphereTable table, Map<String, ShardingSphereDatabase> databases) 
throws SQLException;
 }
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/tables/PgClassTableCollector.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/tables/PgClassTableCollector.java
index b72ff4290b5..5aa7efeedfc 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/tables/PgClassTableCollector.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/tables/PgClassTableCollector.java
@@ -49,11 +49,10 @@ public final class PgClassTableCollector implements 
ShardingSphereStatisticsColl
             + "AND relname NOT LIKE 'matviewmap\\_%' AND relname NOT LIKE 
'mlog\\_%' AND pg_catalog.pg_table_is_visible(oid);";
     
     @Override
-    public Optional<ShardingSphereTableData> collect(final String 
databaseName, final ShardingSphereTable table,
-                                                     final Map<String, 
ShardingSphereDatabase> shardingSphereDatabases) throws SQLException {
-        Collection<ShardingSphereRowData> rows = 
ShardingSphereTableDataCollectorUtils.collectRowData(shardingSphereDatabases.get(databaseName),
+    public Optional<ShardingSphereTableData> collect(final String 
databaseName, final ShardingSphereTable table, final Map<String, 
ShardingSphereDatabase> databases) throws SQLException {
+        Collection<ShardingSphereRowData> rows = 
ShardingSphereTableDataCollectorUtils.collectRowData(databases.get(databaseName),
                 table, 
Arrays.stream(COLUMN_NAMES.split(",")).map(String::trim).collect(Collectors.toList()),
 SELECT_SQL);
-        Collection<ShardingSphereRowData> rowData = decorateTableName(rows, 
table, shardingSphereDatabases.get(databaseName).getRuleMetaData().getRules());
+        Collection<ShardingSphereRowData> rowData = decorateTableName(rows, 
table, databases.get(databaseName).getRuleMetaData().getRules());
         ShardingSphereTableData result = new ShardingSphereTableData(PG_CLASS);
         result.getRows().addAll(rowData);
         return Optional.of(result);
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/tables/PgNamespaceTableCollector.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/tables/PgNamespaceTableCollector.java
index bdea1de566b..ae28d64811a 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/tables/PgNamespaceTableCollector.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/tables/PgNamespaceTableCollector.java
@@ -43,9 +43,8 @@ public final class PgNamespaceTableCollector implements 
ShardingSphereStatistics
     private static final String SELECT_SQL = "SELECT " + COLUMN_NAMES + " FROM 
pg_catalog.pg_namespace";
     
     @Override
-    public Optional<ShardingSphereTableData> collect(final String 
databaseName, final ShardingSphereTable table,
-                                                     final Map<String, 
ShardingSphereDatabase> shardingSphereDatabases) throws SQLException {
-        Collection<ShardingSphereRowData> rows = 
ShardingSphereTableDataCollectorUtils.collectRowData(shardingSphereDatabases.get(databaseName),
+    public Optional<ShardingSphereTableData> collect(final String 
databaseName, final ShardingSphereTable table, final Map<String, 
ShardingSphereDatabase> databases) throws SQLException {
+        Collection<ShardingSphereRowData> rows = 
ShardingSphereTableDataCollectorUtils.collectRowData(databases.get(databaseName),
                 table, 
Arrays.stream(COLUMN_NAMES.split(",")).map(String::trim).collect(Collectors.toList()),
 SELECT_SQL);
         ShardingSphereTableData result = new 
ShardingSphereTableData(PG_NAMESPACE);
         result.getRows().addAll(rows);
diff --git 
a/kernel/schedule/core/src/test/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectorFixture.java
 
b/kernel/schedule/core/src/test/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectorFixture.java
index e2a8df705ff..c9292d19ccc 100644
--- 
a/kernel/schedule/core/src/test/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectorFixture.java
+++ 
b/kernel/schedule/core/src/test/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectorFixture.java
@@ -34,8 +34,7 @@ import java.util.Optional;
 public final class StatisticsCollectorFixture implements 
ShardingSphereStatisticsCollector {
     
     @Override
-    public Optional<ShardingSphereTableData> collect(final String 
databaseName, final ShardingSphereTable table,
-                                                     final Map<String, 
ShardingSphereDatabase> shardingSphereDatabases) throws SQLException {
+    public Optional<ShardingSphereTableData> collect(final String 
databaseName, final ShardingSphereTable table, final Map<String, 
ShardingSphereDatabase> databases) throws SQLException {
         ShardingSphereTableData shardingSphereTableData = new 
ShardingSphereTableData("test_table");
         shardingSphereTableData.getRows().add(new 
ShardingSphereRowData(Arrays.asList("1", "2")));
         return Optional.of(shardingSphereTableData);

Reply via email to