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 3151cd7fc98 Refactor usage of DatabaseStatistics.schemaStatisticsMap 
(#34435)
3151cd7fc98 is described below

commit 3151cd7fc9898a821127bea6a246f0f23c5cfa0f
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Jan 23 14:14:55 2025 +0800

    Refactor usage of DatabaseStatistics.schemaStatisticsMap (#34435)
    
    * Refactor usage of DatabaseStatistics.schemaStatisticsMap
    
    * Remove useless YamlShardingSphereTableStatisticsSwapper
---
 .../data/pojo/YamlShardingSphereTableData.java     | 36 --------------
 .../YamlShardingSphereTableStatisticsSwapper.java  | 57 ----------------------
 ...ShardingSphereDefaultStatisticsBuilderTest.java |  4 +-
 .../dialect/PostgreSQLStatisticsAppenderTest.java  |  4 +-
 .../ShardingSphereStatisticsPersistService.java    |  4 +-
 .../ShardingSphereStatisticsRefreshEngineTest.java |  4 +-
 .../ClusterMetaDataManagerPersistService.java      |  4 +-
 7 files changed, 10 insertions(+), 103 deletions(-)

diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/data/pojo/YamlShardingSphereTableData.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/data/pojo/YamlShardingSphereTableData.java
deleted file mode 100644
index acea0a16556..00000000000
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/data/pojo/YamlShardingSphereTableData.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.yaml.data.pojo;
-
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration;
-
-import java.util.Collection;
-
-/**
- * ShardingSphere table data.
- */
-@Getter
-@Setter
-public final class YamlShardingSphereTableData implements YamlConfiguration {
-    
-    private String name;
-    
-    private Collection<YamlShardingSphereRowData> rowData;
-}
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/data/swapper/YamlShardingSphereTableStatisticsSwapper.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/data/swapper/YamlShardingSphereTableStatisticsSwapper.java
deleted file mode 100644
index c4277b2ef81..00000000000
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/data/swapper/YamlShardingSphereTableStatisticsSwapper.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.yaml.data.swapper;
-
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.metadata.statistics.TableStatistics;
-import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
-import 
org.apache.shardingsphere.infra.util.yaml.swapper.YamlConfigurationSwapper;
-import 
org.apache.shardingsphere.infra.yaml.data.pojo.YamlShardingSphereRowData;
-import 
org.apache.shardingsphere.infra.yaml.data.pojo.YamlShardingSphereTableData;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * YAML ShardingSphere statistics swapper.
- */
-@RequiredArgsConstructor
-public final class YamlShardingSphereTableStatisticsSwapper implements 
YamlConfigurationSwapper<YamlShardingSphereTableData, TableStatistics> {
-    
-    private final List<ShardingSphereColumn> columns;
-    
-    @Override
-    public YamlShardingSphereTableData swapToYamlConfiguration(final 
TableStatistics data) {
-        YamlShardingSphereTableData result = new YamlShardingSphereTableData();
-        result.setName(data.getName());
-        Collection<YamlShardingSphereRowData> yamlShardingSphereRowData = new 
LinkedList<>();
-        data.getRows().forEach(rowData -> yamlShardingSphereRowData.add(new 
YamlShardingSphereRowStatisticsSwapper(columns).swapToYamlConfiguration(rowData)));
-        result.setRowData(yamlShardingSphereRowData);
-        return result;
-    }
-    
-    @Override
-    public TableStatistics swapToObject(final YamlShardingSphereTableData 
yamlConfig) {
-        TableStatistics result = new TableStatistics(yamlConfig.getName());
-        if (null != yamlConfig.getRowData()) {
-            yamlConfig.getRowData().forEach(yamlRowData -> 
result.getRows().add(new 
YamlShardingSphereRowStatisticsSwapper(columns).swapToObject(yamlRowData)));
-        }
-        return result;
-    }
-}
diff --git 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/statistics/builder/ShardingSphereDefaultStatisticsBuilderTest.java
 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/statistics/builder/ShardingSphereDefaultStatisticsBuilderTest.java
index cceef253d46..29bab9372d4 100644
--- 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/statistics/builder/ShardingSphereDefaultStatisticsBuilderTest.java
+++ 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/statistics/builder/ShardingSphereDefaultStatisticsBuilderTest.java
@@ -31,8 +31,8 @@ class ShardingSphereDefaultStatisticsBuilderTest {
     void assertBuild() {
         DatabaseStatistics databaseStatistics = new 
ShardingSphereDefaultStatisticsBuilder().build(mockDatabase());
         
assertTrue(databaseStatistics.getSchemaStatisticsMap().containsKey("shardingsphere"));
-        
assertTrue(databaseStatistics.getSchemaStatisticsMap().get("shardingsphere").getTableStatisticsMap().containsKey("cluster_information"));
-        
assertTrue(databaseStatistics.getSchemaStatisticsMap().get("shardingsphere").getTableStatisticsMap().containsKey("sharding_table_statistics"));
+        
assertTrue(databaseStatistics.getSchemaStatistics("shardingsphere").containsTableStatistics("cluster_information"));
+        
assertTrue(databaseStatistics.getSchemaStatistics("shardingsphere").containsTableStatistics("sharding_table_statistics"));
     }
     
     private ShardingSphereDatabase mockDatabase() {
diff --git 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/statistics/builder/dialect/PostgreSQLStatisticsAppenderTest.java
 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/statistics/builder/dialect/PostgreSQLStatisticsAppenderTest.java
index e0e90153dd9..79dd4d9c41b 100644
--- 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/statistics/builder/dialect/PostgreSQLStatisticsAppenderTest.java
+++ 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/statistics/builder/dialect/PostgreSQLStatisticsAppenderTest.java
@@ -38,8 +38,8 @@ class PostgreSQLStatisticsAppenderTest {
         ShardingSphereDatabase database = mockDatabase();
         DatabaseStatistics databaseStatistics = new 
ShardingSphereDefaultStatisticsBuilder().build(database);
         new PostgreSQLStatisticsAppender().append(databaseStatistics, 
database);
-        
assertTrue(databaseStatistics.getSchemaStatisticsMap().containsKey("pg_catalog"));
-        
assertTrue(databaseStatistics.getSchemaStatisticsMap().get("pg_catalog").getTableStatisticsMap().containsKey("pg_class"));
+        assertTrue(databaseStatistics.containsSchemaStatistics("pg_catalog"));
+        
assertTrue(databaseStatistics.getSchemaStatistics("pg_catalog").containsTableStatistics("pg_class"));
     }
     
     private ShardingSphereDatabase mockDatabase() {
diff --git 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/data/ShardingSphereStatisticsPersistService.java
 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/data/ShardingSphereStatisticsPersistService.java
index b0dab938ecd..46982a3b35f 100644
--- 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/data/ShardingSphereStatisticsPersistService.java
+++ 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/data/ShardingSphereStatisticsPersistService.java
@@ -60,7 +60,7 @@ public final class ShardingSphereStatisticsPersistService {
         }
         ShardingSphereStatistics result = new ShardingSphereStatistics();
         for (String each : 
databaseNames.stream().filter(metaData::containsDatabase).collect(Collectors.toList()))
 {
-            result.getDatabaseStatisticsMap().put(each, 
load(metaData.getDatabase(each)));
+            result.putDatabaseStatistics(each, 
load(metaData.getDatabase(each)));
         }
         return result;
     }
@@ -77,7 +77,7 @@ public final class ShardingSphereStatisticsPersistService {
         SchemaStatistics result = new SchemaStatistics();
         for (String each : 
repository.getChildrenKeys(ShardingSphereStatisticsNodePath.getTableRootPath(databaseName,
 schema.getName())).stream().filter(schema::containsTable)
                 .collect(Collectors.toList())) {
-            result.getTableStatisticsMap().put(each, 
tableRowDataPersistService.load(databaseName, schema.getName(), 
schema.getTable(each)));
+            result.putTableStatistics(each, 
tableRowDataPersistService.load(databaseName, schema.getName(), 
schema.getTable(each)));
             
         }
         return result;
diff --git 
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/ShardingSphereStatisticsRefreshEngineTest.java
 
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/ShardingSphereStatisticsRefreshEngineTest.java
index 13de2b05da4..acead823113 100644
--- 
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/ShardingSphereStatisticsRefreshEngineTest.java
+++ 
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/ShardingSphereStatisticsRefreshEngineTest.java
@@ -67,9 +67,9 @@ class ShardingSphereStatisticsRefreshEngineTest {
         ShardingSphereStatistics result = new ShardingSphereStatistics();
         DatabaseStatistics databaseStatistics = new DatabaseStatistics();
         SchemaStatistics schemaStatistics = new SchemaStatistics();
-        databaseStatistics.getSchemaStatisticsMap().put("foo_schema", 
schemaStatistics);
+        databaseStatistics.putSchemaStatistics("foo_schema", schemaStatistics);
         TableStatistics tableStatistics = new TableStatistics("test_table");
-        schemaStatistics.getTableStatisticsMap().put("test_table", 
tableStatistics);
+        schemaStatistics.putTableStatistics("test_table", tableStatistics);
         result.getDatabaseStatisticsMap().put("foo_db", databaseStatistics);
         return result;
     }
diff --git 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterMetaDataManagerPersistService.java
 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterMetaDataManagerPersistService.java
index 4721e0b89cc..410437d211d 100644
--- 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterMetaDataManagerPersistService.java
+++ 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterMetaDataManagerPersistService.java
@@ -183,7 +183,7 @@ public final class ClusterMetaDataManagerPersistService 
implements MetaDataManag
     }
     
     private void afterStorageUnitsAltered(final String databaseName, final 
MetaDataContexts originalMetaDataContexts, final MetaDataContexts 
reloadMetaDataContexts) {
-        
Optional.ofNullable(reloadMetaDataContexts.getStatistics().getDatabaseStatisticsMap().get(databaseName))
+        
Optional.ofNullable(reloadMetaDataContexts.getStatistics().getDatabaseStatistics(databaseName))
                 .ifPresent(optional -> 
optional.getSchemaStatisticsMap().forEach((schemaName, schemaStatistics) -> 
metaDataPersistService.getShardingSphereStatisticsPersistService()
                         
.persist(originalMetaDataContexts.getMetaData().getDatabase(databaseName), 
schemaName, schemaStatistics)));
         metaDataPersistService.persistReloadDatabaseByAlter(databaseName, 
reloadMetaDataContexts.getMetaData().getDatabase(databaseName),
@@ -193,7 +193,7 @@ public final class ClusterMetaDataManagerPersistService 
implements MetaDataManag
     private void afterStorageUnitsDropped(final String databaseName, final 
MetaDataContexts originalMetaDataContexts, final MetaDataContexts 
reloadMetaDataContexts) {
         
reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getAllSchemas().forEach(each
 -> metaDataPersistService.getDatabaseMetaDataFacade()
                 
.getSchema().alterByRuleDropped(reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getName(),
 each));
-        
Optional.ofNullable(reloadMetaDataContexts.getStatistics().getDatabaseStatisticsMap().get(databaseName))
+        
Optional.ofNullable(reloadMetaDataContexts.getStatistics().getDatabaseStatistics(databaseName))
                 .ifPresent(optional -> 
optional.getSchemaStatisticsMap().forEach((schemaName, schemaStatistics) -> 
metaDataPersistService.getShardingSphereStatisticsPersistService()
                         
.persist(originalMetaDataContexts.getMetaData().getDatabase(databaseName), 
schemaName, schemaStatistics)));
         metaDataPersistService.persistReloadDatabaseByDrop(databaseName, 
reloadMetaDataContexts.getMetaData().getDatabase(databaseName),

Reply via email to