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 2714c82  Bug fix for `explain SQL` routing (#6978)
2714c82 is described below

commit 2714c82a6a5d34731960d0c84bbad416de5d056e
Author: Juan Pan(Trista) <[email protected]>
AuthorDate: Fri Aug 21 18:26:50 2020 +0800

    Bug fix for `explain SQL` routing (#6978)
    
    * Bug fix for `explain SQL` routing
    
    * Add unit test
---
 .../route/engine/type/unicast/ShardingUnicastRoutingEngine.java   | 3 ++-
 .../engine/type/unicast/ShardingUnicastRoutingEngineTest.java     | 8 +++++---
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngine.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngine.java
index 224bff5..03a9d79 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngine.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngine.java
@@ -65,7 +65,8 @@ public final class ShardingUnicastRoutingEngine implements 
ShardingRouteEngine {
                 return result;
             }
             DataNode dataNode = shardingRule.getDataNode(logicTableName);
-            result.getRouteUnits().add(new RouteUnit(dataSourceMapper, 
Collections.singletonList(new RouteMapper(logicTableName, 
dataNode.getTableName()))));
+            result.getRouteUnits().add(new RouteUnit(new 
RouteMapper(dataNode.getDataSourceName(), dataNode.getDataSourceName()),
+                    Collections.singletonList(new RouteMapper(logicTableName, 
dataNode.getTableName()))));
         } else {
             List<RouteMapper> tableMappers = new 
ArrayList<>(logicTables.size());
             Set<String> availableDatasourceNames = null;
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngineTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngineTest.java
index 3d4b139..f4d18a7 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngineTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngineTest.java
@@ -17,11 +17,11 @@
 
 package org.apache.shardingsphere.sharding.route.engine.type.unicast;
 
+import 
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException;
+import org.apache.shardingsphere.infra.route.context.RouteResult;
 import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
-import 
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException;
-import org.apache.shardingsphere.infra.route.context.RouteResult;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -32,6 +32,7 @@ import java.util.Set;
 
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertThat;
 
 public final class ShardingUnicastRoutingEngineTest {
@@ -43,7 +44,7 @@ public final class ShardingUnicastRoutingEngineTest {
         ShardingRuleConfiguration shardingRuleConfig = new 
ShardingRuleConfiguration();
         shardingRuleConfig.getTables().add(new 
ShardingTableRuleConfiguration("t_order", "ds${0..1}.t_order_${0..2}"));
         shardingRuleConfig.getBroadcastTables().add("t_config");
-        shardingRule = new ShardingRule(shardingRuleConfig, 
Arrays.asList("ds0", "ds1"));
+        shardingRule = new ShardingRule(shardingRuleConfig, 
Arrays.asList("ds0", "ds1", "ds2"));
     }
     
     @Test
@@ -52,6 +53,7 @@ public final class ShardingUnicastRoutingEngineTest {
         RouteResult routeResult = unicastRoutingEngine.route(shardingRule);
         assertThat(routeResult, instanceOf(RouteResult.class));
         assertThat(routeResult.getRouteUnits().size(), is(1));
+        
assertFalse(routeResult.getRouteUnits().iterator().next().getDataSourceMapper().getLogicName().equalsIgnoreCase("ds2"));
     }
 
     @Test

Reply via email to