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 eb2761f1d57 Support filter loading when there are single tables with 
the same name (#27292)
eb2761f1d57 is described below

commit eb2761f1d571325a002255eeefa8929f2f3713e6
Author: Raigor <[email protected]>
AuthorDate: Wed Jul 19 15:06:35 2023 +0800

    Support filter loading when there are single tables with the same name 
(#27292)
    
    * Fix #27290, support filter loading when there are single tables with the 
same name
    
    * Fix #27290, support filter loading when there are single tables with the 
same name
    
    * Fix remove test.
---
 .../single/datanode/SingleTableDataNodeLoader.java | 34 +++++++++++++++-------
 1 file changed, 24 insertions(+), 10 deletions(-)

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 a93a912d948..04ad48675b6 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
@@ -117,27 +117,41 @@ public final class SingleTableDataNodeLoader {
                                                                             
final Map<String, Map<String, Collection<String>>> configuredTableMap) {
         Map<String, Collection<DataNode>> result = new ConcurrentHashMap<>();
         for (Entry<String, Collection<DataNode>> entry : 
actualDataNodes.entrySet()) {
-            DataNode actualDataNode = entry.getValue().iterator().next();
-            if 
(featureRequiredSingleTables.contains(actualDataNode.getTableName())) {
-                result.put(actualDataNode.getTableName(), entry.getValue());
-                continue;
+            Collection<DataNode> singleNode = 
loadSpecifiedDataNode(entry.getValue(), featureRequiredSingleTables, 
configuredTableMap);
+            if (!singleNode.isEmpty()) {
+                result.put(entry.getKey(), singleNode);
             }
-            Map<String, Collection<String>> configuredTablesForDataSource = 
configuredTableMap.get(actualDataNode.getDataSourceName());
+        }
+        return result;
+    }
+    
+    private static Collection<DataNode> loadSpecifiedDataNode(final 
Collection<DataNode> dataNodes, final Collection<String> 
featureRequiredSingleTables,
+                                                              final 
Map<String, Map<String, Collection<String>>> configuredTableMap) {
+        for (final DataNode each : dataNodes) {
+            if (featureRequiredSingleTables.contains(each.getTableName())) {
+                return getSingleDataNodeCollection(each);
+            }
+            Map<String, Collection<String>> configuredTablesForDataSource = 
configuredTableMap.get(each.getDataSourceName());
             if (null == configuredTablesForDataSource || 
configuredTablesForDataSource.isEmpty()) {
                 continue;
             }
             if 
(configuredTablesForDataSource.containsKey(SingleTableConstants.ASTERISK)) {
-                result.put(actualDataNode.getTableName(), entry.getValue());
-                continue;
+                return getSingleDataNodeCollection(each);
             }
-            Collection<String> configuredTablesForSchema = 
configuredTablesForDataSource.get(actualDataNode.getSchemaName());
+            Collection<String> configuredTablesForSchema = 
configuredTablesForDataSource.get(each.getSchemaName());
             if (null == configuredTablesForSchema || 
configuredTablesForSchema.isEmpty()) {
                 continue;
             }
-            if 
(configuredTablesForSchema.contains(SingleTableConstants.ASTERISK) || 
configuredTablesForSchema.contains(actualDataNode.getTableName())) {
-                result.put(actualDataNode.getTableName(), entry.getValue());
+            if 
(configuredTablesForSchema.contains(SingleTableConstants.ASTERISK) || 
configuredTablesForSchema.contains(each.getTableName())) {
+                return getSingleDataNodeCollection(each);
             }
         }
+        return Collections.emptyList();
+    }
+    
+    private static Collection<DataNode> getSingleDataNodeCollection(final 
DataNode dataNode) {
+        Collection<DataNode> result = new LinkedList<>();
+        result.add(dataNode);
         return result;
     }
     

Reply via email to