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

chengzhang 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 0be86d3404e Move getAggregatedDataSourceMap from SingleTableLoadUtils 
to PhysicalResourceAggregator (#33202)
0be86d3404e is described below

commit 0be86d3404e1c0b4a951b7522ad6fd422bc30950
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Thu Oct 10 16:53:57 2024 +0800

    Move getAggregatedDataSourceMap from SingleTableLoadUtils to 
PhysicalResourceAggregator (#33202)
    
    * Move getAggregatedDataSourceMap from SingleTableLoadUtils to 
PhysicalResourceAggregator
    
    * fix unit test
---
 .../sharding/rule/ShardingTable.java               |  9 ---
 .../resource/PhysicalResourceAggregator.java       | 68 ++++++++++++++++++++++
 .../data/loader/type/SchemaMetaDataLoader.java     |  4 +-
 .../data/loader/MySQLSchemaMetaDataLoaderTest.java |  4 +-
 .../loader/OpenGaussSchemaMetaDataLoaderTest.java  |  4 +-
 .../loader/PostgreSQLSchemaMetaDataLoaderTest.java |  4 +-
 .../single/datanode/SingleTableDataNodeLoader.java |  2 +-
 .../SingleRuleConfigurationDecorator.java          |  3 +-
 .../shardingsphere/single/rule/SingleRule.java     |  4 +-
 .../single/util/SingleTableLoadUtils.java          | 36 ------------
 .../query/ShowUnloadedSingleTablesExecutor.java    |  3 +-
 .../handler/update/LoadSingleTableExecutor.java    |  4 +-
 .../update/LoadSingleTableExecutorTest.java        |  5 +-
 13 files changed, 88 insertions(+), 62 deletions(-)

diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingTable.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingTable.java
index b0adfebbf65..d5ad5b7efdd 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingTable.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingTable.java
@@ -214,15 +214,6 @@ public final class ShardingTable {
         return DataNodeUtils.getDataNodeGroups(actualDataNodes);
     }
     
-    /**
-     * Get actual data source names.
-     *
-     * @return actual data source names
-     */
-    public Collection<String> getActualDataSourceNames() {
-        return actualDataSourceNames;
-    }
-    
     /**
      * Get actual table names via target data source name.
      *
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/PhysicalResourceAggregator.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/PhysicalResourceAggregator.java
new file mode 100644
index 00000000000..aa34579181e
--- /dev/null
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/PhysicalResourceAggregator.java
@@ -0,0 +1,68 @@
+/*
+ * 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.metadata.database.resource;
+
+import com.cedarsoftware.util.CaseInsensitiveMap;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import 
org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute;
+
+import javax.sql.DataSource;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+
+/**
+ * Physical resource aggregator.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class PhysicalResourceAggregator {
+    
+    /**
+     * Get aggregated resources.
+     *
+     * @param dataSourceMap data source map
+     * @param builtRules built rules
+     * @return aggregated resources
+     */
+    public static Map<String, DataSource> getAggregatedResources(final 
Map<String, DataSource> dataSourceMap, final Collection<ShardingSphereRule> 
builtRules) {
+        Map<String, DataSource> result = new 
CaseInsensitiveMap<>(dataSourceMap);
+        for (ShardingSphereRule each : builtRules) {
+            Optional<DataSourceMapperRuleAttribute> ruleAttribute = 
each.getAttributes().findAttribute(DataSourceMapperRuleAttribute.class);
+            if (ruleAttribute.isPresent()) {
+                result = getAggregatedResources(result, ruleAttribute.get());
+            }
+        }
+        return result;
+    }
+    
+    private static Map<String, DataSource> getAggregatedResources(final 
Map<String, DataSource> dataSourceMap, final DataSourceMapperRuleAttribute 
ruleAttribute) {
+        Map<String, DataSource> result = new CaseInsensitiveMap<>();
+        for (Entry<String, Collection<String>> entry : 
ruleAttribute.getDataSourceMapper().entrySet()) {
+            for (String each : entry.getValue()) {
+                if (dataSourceMap.containsKey(each)) {
+                    result.putIfAbsent(entry.getKey(), 
dataSourceMap.remove(each));
+                }
+            }
+        }
+        result.putAll(dataSourceMap);
+        return result;
+    }
+}
diff --git 
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/data/loader/type/SchemaMetaDataLoader.java
 
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/data/loader/type/SchemaMetaDataLoader.java
index c3772ba51f9..7ddfceb73a7 100644
--- 
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/data/loader/type/SchemaMetaDataLoader.java
+++ 
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/data/loader/type/SchemaMetaDataLoader.java
@@ -63,8 +63,8 @@ public final class SchemaMetaDataLoader {
      * @return loaded schema table names
      * @throws SQLException SQL exception
      */
-    public static Map<String, Collection<String>> 
loadSchemaTableNamesByExcludedTables(final String databaseName, final 
DatabaseType databaseType, final DataSource dataSource,
-                                                                               
        final Collection<String> excludedTables) throws SQLException {
+    public static Map<String, Collection<String>> loadSchemaTableNames(final 
String databaseName, final DatabaseType databaseType, final DataSource 
dataSource,
+                                                                       final 
Collection<String> excludedTables) throws SQLException {
         try (MetaDataLoaderConnection connection = new 
MetaDataLoaderConnection(databaseType, dataSource.getConnection())) {
             Collection<String> schemaNames = loadSchemaNames(connection, 
databaseType);
             DialectDatabaseMetaData dialectDatabaseMetaData = new 
DatabaseTypeRegistry(databaseType).getDialectDatabaseMetaData();
diff --git 
a/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/metadata/data/loader/MySQLSchemaMetaDataLoaderTest.java
 
b/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/metadata/data/loader/MySQLSchemaMetaDataLoaderTest.java
index a0e15415ccb..19bd5d4af2a 100644
--- 
a/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/metadata/data/loader/MySQLSchemaMetaDataLoaderTest.java
+++ 
b/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/metadata/data/loader/MySQLSchemaMetaDataLoaderTest.java
@@ -74,9 +74,9 @@ class MySQLSchemaMetaDataLoaderTest {
     }
     
     @Test
-    void assertLoadSchemaTableNamesByExcludedTables() throws SQLException {
+    void assertLoadSchemaTableNames() throws SQLException {
         Map<String, Collection<String>> schemaTableNames = 
Collections.singletonMap(DefaultDatabase.LOGIC_NAME, 
Collections.singletonList("tbl"));
-        
assertThat(SchemaMetaDataLoader.loadSchemaTableNamesByExcludedTables(DefaultDatabase.LOGIC_NAME,
+        
assertThat(SchemaMetaDataLoader.loadSchemaTableNames(DefaultDatabase.LOGIC_NAME,
                 TypedSPILoader.getService(DatabaseType.class, "MySQL"), 
dataSource, Collections.emptyList()), is(schemaTableNames));
     }
     
diff --git 
a/infra/database/type/opengauss/src/test/java/org/apache/shardingsphere/infra/database/opengauss/metadata/data/loader/OpenGaussSchemaMetaDataLoaderTest.java
 
b/infra/database/type/opengauss/src/test/java/org/apache/shardingsphere/infra/database/opengauss/metadata/data/loader/OpenGaussSchemaMetaDataLoaderTest.java
index 2db8141d3e0..a7adf9c9124 100644
--- 
a/infra/database/type/opengauss/src/test/java/org/apache/shardingsphere/infra/database/opengauss/metadata/data/loader/OpenGaussSchemaMetaDataLoaderTest.java
+++ 
b/infra/database/type/opengauss/src/test/java/org/apache/shardingsphere/infra/database/opengauss/metadata/data/loader/OpenGaussSchemaMetaDataLoaderTest.java
@@ -76,8 +76,8 @@ class OpenGaussSchemaMetaDataLoaderTest {
     }
     
     @Test
-    void assertLoadSchemaTableNamesByExcludedTables() throws SQLException {
-        
assertThat(SchemaMetaDataLoader.loadSchemaTableNamesByExcludedTables(DefaultDatabase.LOGIC_NAME,
+    void assertLoadSchemaTableNames() throws SQLException {
+        
assertThat(SchemaMetaDataLoader.loadSchemaTableNames(DefaultDatabase.LOGIC_NAME,
                 TypedSPILoader.getService(DatabaseType.class, "openGauss"), 
dataSource, Collections.emptyList()), is(createSchemaTableNames()));
     }
     
diff --git 
a/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/metadata/data/loader/PostgreSQLSchemaMetaDataLoaderTest.java
 
b/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/metadata/data/loader/PostgreSQLSchemaMetaDataLoaderTest.java
index b5540694b1a..8059daaba30 100644
--- 
a/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/metadata/data/loader/PostgreSQLSchemaMetaDataLoaderTest.java
+++ 
b/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/metadata/data/loader/PostgreSQLSchemaMetaDataLoaderTest.java
@@ -76,8 +76,8 @@ class PostgreSQLSchemaMetaDataLoaderTest {
     }
     
     @Test
-    void assertLoadSchemaTableNamesByExcludedTables() throws SQLException {
-        
assertThat(SchemaMetaDataLoader.loadSchemaTableNamesByExcludedTables(DefaultDatabase.LOGIC_NAME,
+    void assertLoadSchemaTableNames() throws SQLException {
+        
assertThat(SchemaMetaDataLoader.loadSchemaTableNames(DefaultDatabase.LOGIC_NAME,
                 TypedSPILoader.getService(DatabaseType.class, "PostgreSQL"), 
dataSource, Collections.emptyList()), is(createSchemaTableNames()));
     }
     
diff --git 
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/datanode/SingleTableDataNodeLoader.java
 
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/datanode/SingleTableDataNodeLoader.java
index 5c07eb869ea..bc6c639ab0e 100644
--- 
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/datanode/SingleTableDataNodeLoader.java
+++ 
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/datanode/SingleTableDataNodeLoader.java
@@ -182,7 +182,7 @@ public final class SingleTableDataNodeLoader {
     public static Map<String, Collection<String>> loadSchemaTableNames(final 
String databaseName, final DatabaseType storageType,
                                                                        final 
DataSource dataSource, final String dataSourceName, final Collection<String> 
excludedTables) {
         try {
-            return 
SchemaMetaDataLoader.loadSchemaTableNamesByExcludedTables(databaseName, 
storageType, dataSource, excludedTables);
+            return SchemaMetaDataLoader.loadSchemaTableNames(databaseName, 
storageType, dataSource, excludedTables);
         } catch (final SQLException ex) {
             throw new SingleTablesLoadingException(databaseName, 
dataSourceName, ex);
         }
diff --git 
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
 
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
index 836476368ab..78e4cdb3911 100644
--- 
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
+++ 
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
@@ -23,6 +23,7 @@ import 
org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
 import org.apache.shardingsphere.infra.datanode.DataNode;
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
+import 
org.apache.shardingsphere.infra.metadata.database.resource.PhysicalResourceAggregator;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
 import org.apache.shardingsphere.single.config.SingleRuleConfiguration;
 import org.apache.shardingsphere.single.constant.SingleTableConstants;
@@ -62,7 +63,7 @@ public final class SingleRuleConfigurationDecorator 
implements RuleConfiguration
         if (!isExpandRequired(splitTables)) {
             return splitTables;
         }
-        Map<String, DataSource> aggregatedDataSources = 
SingleTableLoadUtils.getAggregatedDataSourceMap(dataSources, builtRules);
+        Map<String, DataSource> aggregatedDataSources = 
PhysicalResourceAggregator.getAggregatedResources(dataSources, builtRules);
         DatabaseType databaseType = dataSources.isEmpty() ? 
DatabaseTypeEngine.getDefaultStorageType() : 
DatabaseTypeEngine.getStorageType(dataSources.values().iterator().next());
         Collection<String> excludedTables = 
SingleTableLoadUtils.getExcludedTables(builtRules);
         Map<String, Collection<DataNode>> actualDataNodes = 
SingleTableDataNodeLoader.load(databaseName, aggregatedDataSources, 
excludedTables);
diff --git 
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
 
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
index cdd94c7b7c1..200cba9a07a 100644
--- 
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
+++ 
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
@@ -25,6 +25,7 @@ import 
org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
 import org.apache.shardingsphere.infra.datanode.DataNode;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import 
org.apache.shardingsphere.infra.metadata.database.resource.PhysicalResourceAggregator;
 import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedTable;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.util.IndexMetaDataUtils;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
@@ -32,7 +33,6 @@ import 
org.apache.shardingsphere.infra.rule.attribute.RuleAttributes;
 import org.apache.shardingsphere.infra.rule.scope.DatabaseRule;
 import org.apache.shardingsphere.single.config.SingleRuleConfiguration;
 import org.apache.shardingsphere.single.datanode.SingleTableDataNodeLoader;
-import org.apache.shardingsphere.single.util.SingleTableLoadUtils;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
 
 import javax.sql.DataSource;
@@ -70,7 +70,7 @@ public final class SingleRule implements DatabaseRule {
                       final DatabaseType protocolType, final Map<String, 
DataSource> dataSourceMap, final Collection<ShardingSphereRule> builtRules) {
         configuration = ruleConfig;
         defaultDataSource = ruleConfig.getDefaultDataSource().orElse(null);
-        Map<String, DataSource> aggregateDataSourceMap = 
SingleTableLoadUtils.getAggregatedDataSourceMap(dataSourceMap, builtRules);
+        Map<String, DataSource> aggregateDataSourceMap = 
PhysicalResourceAggregator.getAggregatedResources(dataSourceMap, builtRules);
         dataSourceNames = aggregateDataSourceMap.keySet();
         this.protocolType = protocolType;
         singleTableDataNodes = SingleTableDataNodeLoader.load(databaseName, 
protocolType, aggregateDataSourceMap, builtRules, configuration.getTables());
diff --git 
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/util/SingleTableLoadUtils.java
 
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/util/SingleTableLoadUtils.java
index 93603bb281f..8ceb22ba045 100644
--- 
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/util/SingleTableLoadUtils.java
+++ 
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/util/SingleTableLoadUtils.java
@@ -25,16 +25,11 @@ import 
org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
 import org.apache.shardingsphere.infra.datanode.DataNode;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import 
org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute;
 import 
org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute;
 import org.apache.shardingsphere.single.constant.SingleTableConstants;
 
-import javax.sql.DataSource;
 import java.util.Collection;
-import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Optional;
 import java.util.TreeSet;
 
@@ -46,37 +41,6 @@ public final class SingleTableLoadUtils {
     
     private static final String DELIMITER = ",";
     
-    /**
-     * Get aggregated data source map.
-     *
-     * @param dataSourceMap data source map
-     * @param builtRules built rules
-     * @return aggregated data source map
-     */
-    public static Map<String, DataSource> getAggregatedDataSourceMap(final 
Map<String, DataSource> dataSourceMap, final Collection<ShardingSphereRule> 
builtRules) {
-        Map<String, DataSource> result = new LinkedHashMap<>(dataSourceMap);
-        for (ShardingSphereRule each : builtRules) {
-            Optional<DataSourceMapperRuleAttribute> ruleAttribute = 
each.getAttributes().findAttribute(DataSourceMapperRuleAttribute.class);
-            if (ruleAttribute.isPresent()) {
-                result = getAggregatedDataSourceMap(result, 
ruleAttribute.get());
-            }
-        }
-        return result;
-    }
-    
-    private static Map<String, DataSource> getAggregatedDataSourceMap(final 
Map<String, DataSource> dataSourceMap, final DataSourceMapperRuleAttribute 
ruleAttribute) {
-        Map<String, DataSource> result = new LinkedHashMap<>();
-        for (Entry<String, Collection<String>> entry : 
ruleAttribute.getDataSourceMapper().entrySet()) {
-            for (String each : entry.getValue()) {
-                if (dataSourceMap.containsKey(each)) {
-                    result.putIfAbsent(entry.getKey(), 
dataSourceMap.remove(each));
-                }
-            }
-        }
-        result.putAll(dataSourceMap);
-        return result;
-    }
-    
     /**
      * Get excluded tables.
      *
diff --git 
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTablesExecutor.java
 
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTablesExecutor.java
index 58371ab8105..72b4fe68d3c 100644
--- 
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTablesExecutor.java
+++ 
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTablesExecutor.java
@@ -24,6 +24,7 @@ import 
org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecut
 import org.apache.shardingsphere.infra.datanode.DataNode;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import 
org.apache.shardingsphere.infra.metadata.database.resource.PhysicalResourceAggregator;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
 import 
org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute;
 import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -66,7 +67,7 @@ public final class ShowUnloadedSingleTablesExecutor 
implements DistSQLQueryExecu
     
     private Map<String, Collection<DataNode>> getActualDataNodes(final 
ShardingSphereDatabase database) {
         ResourceMetaData resourceMetaData = database.getResourceMetaData();
-        Map<String, DataSource> aggregateDataSourceMap = 
SingleTableLoadUtils.getAggregatedDataSourceMap(
+        Map<String, DataSource> aggregateDataSourceMap = 
PhysicalResourceAggregator.getAggregatedResources(
                 resourceMetaData.getStorageUnits().entrySet().stream()
                         .collect(Collectors.toMap(Entry::getKey, entry -> 
entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, 
LinkedHashMap::new)),
                 database.getRuleMetaData().getRules());
diff --git 
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
 
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
index 8119e19feb7..644adff1042 100644
--- 
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
+++ 
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
@@ -30,6 +30,7 @@ import 
org.apache.shardingsphere.infra.exception.kernel.metadata.resource.storag
 import 
org.apache.shardingsphere.infra.exception.kernel.metadata.resource.storageunit.InvalidStorageUnitStatusException;
 import 
org.apache.shardingsphere.infra.exception.kernel.metadata.resource.storageunit.MissingRequiredStorageUnitsException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import 
org.apache.shardingsphere.infra.metadata.database.resource.PhysicalResourceAggregator;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
 import 
org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute;
 import org.apache.shardingsphere.single.config.SingleRuleConfiguration;
@@ -38,7 +39,6 @@ import 
org.apache.shardingsphere.single.datanode.SingleTableDataNodeLoader;
 import org.apache.shardingsphere.single.distsql.segment.SingleTableSegment;
 import 
org.apache.shardingsphere.single.distsql.statement.rdl.LoadSingleTableStatement;
 import org.apache.shardingsphere.single.rule.SingleRule;
-import org.apache.shardingsphere.single.util.SingleTableLoadUtils;
 
 import javax.sql.DataSource;
 import java.util.Collection;
@@ -113,7 +113,7 @@ public final class LoadSingleTableExecutor implements 
DatabaseRuleCreateExecutor
     private void checkShouldExistActualTables(final LoadSingleTableStatement 
sqlStatement, final Collection<String> storageUnitNames, final String 
defaultSchemaName) {
         Map<String, DataSource> dataSourceMap = 
database.getResourceMetaData().getStorageUnits().entrySet()
                 .stream().collect(Collectors.toMap(Entry::getKey, entry -> 
entry.getValue().getDataSource()));
-        Map<String, DataSource> aggregatedDataSourceMap = 
SingleTableLoadUtils.getAggregatedDataSourceMap(dataSourceMap, 
database.getRuleMetaData().getRules());
+        Map<String, DataSource> aggregatedDataSourceMap = 
PhysicalResourceAggregator.getAggregatedResources(dataSourceMap, 
database.getRuleMetaData().getRules());
         Collection<String> invalidDataSources = 
storageUnitNames.stream().filter(each -> 
!aggregatedDataSourceMap.containsKey(each)).collect(Collectors.toList());
         ShardingSpherePreconditions.checkState(invalidDataSources.isEmpty(), 
() -> new InvalidStorageUnitStatusException(String.format("`%s` is invalid, 
please use `%s`",
                 String.join(",", invalidDataSources), String.join(",", 
aggregatedDataSourceMap.keySet()))));
diff --git 
a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutorTest.java
 
b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutorTest.java
index 2d7adb810bf..c5c3d8ce1fe 100644
--- 
a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutorTest.java
+++ 
b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutorTest.java
@@ -25,6 +25,7 @@ import 
org.apache.shardingsphere.infra.exception.kernel.metadata.TableNotFoundEx
 import 
org.apache.shardingsphere.infra.exception.kernel.metadata.datanode.InvalidDataNodeFormatException;
 import 
org.apache.shardingsphere.infra.exception.kernel.metadata.resource.storageunit.MissingRequiredStorageUnitsException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import 
org.apache.shardingsphere.infra.metadata.database.resource.PhysicalResourceAggregator;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
 import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
@@ -65,7 +66,7 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 @ExtendWith(AutoMockExtension.class)
-@StaticMockSettings({SingleTableDataNodeLoader.class, 
SingleTableLoadUtils.class})
+@StaticMockSettings({SingleTableDataNodeLoader.class, 
SingleTableLoadUtils.class, PhysicalResourceAggregator.class})
 @MockitoSettings(strictness = Strictness.LENIENT)
 class LoadSingleTableExecutorTest {
     
@@ -124,7 +125,7 @@ class LoadSingleTableExecutorTest {
         StorageUnit storageUnit = mock(StorageUnit.class);
         when(storageUnit.getDataSource()).thenReturn(new MockedDataSource());
         
when(database.getResourceMetaData().getStorageUnits()).thenReturn(Collections.singletonMap("foo_ds",
 storageUnit));
-        when(SingleTableLoadUtils.getAggregatedDataSourceMap(any(), 
any())).thenReturn(Collections.singletonMap("foo_ds", new MockedDataSource()));
+        when(PhysicalResourceAggregator.getAggregatedResources(any(), 
any())).thenReturn(Collections.singletonMap("foo_ds", new MockedDataSource()));
         LoadSingleTableStatement sqlStatement = new 
LoadSingleTableStatement(Collections.singleton(new SingleTableSegment("foo_ds", 
"foo_tbl")));
         assertThrows(TableNotFoundException.class, () -> new 
DistSQLUpdateExecuteEngine(sqlStatement, "foo_db", 
mockContextManager(mock(SingleRule.class))).executeUpdate());
     }

Reply via email to