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

panjuan 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 09b27c2  fix execute query exception with broadcast and single table 
(#13258)
09b27c2 is described below

commit 09b27c273d3a7c7fd31a6853b8e4c95c9b669cb0
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Mon Oct 25 18:38:40 2021 +0800

    fix execute query exception with broadcast and single table (#13258)
    
    * rename param
    
    * fix execute query exception with broadcast and single table
    
    * fix test case
---
 .../route/engine/type/ShardingRouteEngineFactory.java         | 11 +++++------
 .../route/engine/type/ShardingRouteEngineFactoryTest.java     |  4 ++--
 .../shardingsphere/singletable/rule/SingleTableRule.java      |  4 ++--
 .../src/test/resources/scenario/sharding/case/select.xml      |  5 +++++
 4 files changed, 14 insertions(+), 10 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
index 4d2cf5c..64482b8 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
@@ -178,11 +178,11 @@ public final class ShardingRouteEngineFactory {
         if (sqlStatementContext.getSqlStatement() instanceof DMLStatement && 
shardingConditions.isAlwaysFalse() || tableNames.isEmpty()) {
             return new ShardingUnicastRoutingEngine(tableNames);
         }
-        Collection<String> shardingRuleTableNames = 
shardingRule.getShardingRuleTableNames(tableNames);
-        if (shardingRuleTableNames.isEmpty()) {
+        Collection<String> shardingLogicTableNames = 
shardingRule.getShardingLogicTableNames(tableNames);
+        if (shardingLogicTableNames.isEmpty()) {
             return new ShardingIgnoreRoutingEngine();
         }
-        return getDQLRouteEngineForShardingTable(shardingRule, 
sqlStatementContext, shardingConditions, shardingRuleTableNames, props);
+        return getDQLRouteEngineForShardingTable(shardingRule, 
sqlStatementContext, shardingConditions, shardingLogicTableNames, props);
     }
     
     private static ShardingRouteEngine getDQLRouteEngineForShardingTable(final 
ShardingRule shardingRule, final SQLStatementContext<?> sqlStatementContext, 
@@ -218,10 +218,9 @@ public final class ShardingRouteEngineFactory {
         if (select.isContainsSubquery() || select.isContainsHaving() || 
select.isContainsPartialDistinctAggregation()) {
             return true;
         }
-        Collection<String> shardingTableNames = 
shardingRule.getShardingLogicTableNames(tableNames);
-        if (!select.isContainsJoinQuery() || 
shardingRule.isAllTablesInSameDataSource(shardingTableNames)) {
+        if (!select.isContainsJoinQuery() || 
shardingRule.isAllTablesInSameDataSource(tableNames)) {
             return false;
         }
-        return shardingTableNames.size() > 1 && 
!shardingRule.isAllBindingTables(shardingTableNames);
+        return tableNames.size() > 1 && 
!shardingRule.isAllBindingTables(tableNames);
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java
index 755dc67..c9233df 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java
@@ -254,7 +254,7 @@ public final class ShardingRouteEngineFactoryTest {
         SQLStatement sqlStatement = mock(SQLStatement.class);
         when(sqlStatementContext.getSqlStatement()).thenReturn(sqlStatement);
         tableNames.add("");
-        
when(shardingRule.getShardingRuleTableNames(sqlStatementContext.getTablesContext().getTableNames())).thenReturn(tableNames);
+        
when(shardingRule.getShardingLogicTableNames(sqlStatementContext.getTablesContext().getTableNames())).thenReturn(tableNames);
         when(shardingRule.isAllShardingTables(tableNames)).thenReturn(true);
         ShardingRouteEngine actual = 
ShardingRouteEngineFactory.newInstance(shardingRule, metaData, 
sqlStatementContext, shardingConditions, props);
         assertThat(actual, instanceOf(ShardingStandardRoutingEngine.class));
@@ -266,7 +266,7 @@ public final class ShardingRouteEngineFactoryTest {
         when(sqlStatementContext.getSqlStatement()).thenReturn(sqlStatement);
         tableNames.add("1");
         tableNames.add("2");
-        
when(shardingRule.getShardingRuleTableNames(tableNames)).thenReturn(tableNames);
+        
when(shardingRule.getShardingLogicTableNames(tableNames)).thenReturn(tableNames);
         ShardingRouteEngine actual = 
ShardingRouteEngineFactory.newInstance(shardingRule, metaData, 
sqlStatementContext, shardingConditions, props);
         assertThat(actual, instanceOf(ShardingComplexRoutingEngine.class));
     }
diff --git 
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
 
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
index f31e231..a66e7f7 100644
--- 
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
+++ 
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
@@ -66,9 +66,9 @@ public final class SingleTableRule implements SchemaRule, 
DataNodeContainedRule,
         return result;
     }
     
-    private Map<String, DataSource> getAggregateDataSourceMap(final 
Map<String, DataSource> dataSourceMap, final DataSourceContainedRule 
builtRules) {
+    private Map<String, DataSource> getAggregateDataSourceMap(final 
Map<String, DataSource> dataSourceMap, final DataSourceContainedRule builtRule) 
{
         Map<String, DataSource> result = new LinkedHashMap<>();
-        for (Entry<String, Collection<String>> entry : 
builtRules.getDataSourceMapper().entrySet()) {
+        for (Entry<String, Collection<String>> entry : 
builtRule.getDataSourceMapper().entrySet()) {
             for (String each : entry.getValue()) {
                 if (dataSourceMap.containsKey(each)) {
                     result.putIfAbsent(entry.getKey(), 
dataSourceMap.remove(each));
diff --git 
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml
 
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml
index b735cec..4a96768 100644
--- 
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml
+++ 
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml
@@ -511,4 +511,9 @@
         <input sql="SELECT * FROM (SELECT id, content FROM t_user WHERE id = ? 
AND content IN (SELECT content FROM t_user_extend WHERE user_id = ?)) AS temp" 
parameters="1, 1"/>
         <output sql="SELECT * FROM (SELECT id, content FROM t_user_1 WHERE id 
= ? AND content IN (SELECT content FROM t_user_extend_1 WHERE user_id = ?)) AS 
temp" parameters="1, 1"/>
     </rewrite-assertion>
+    
+    <rewrite-assertion id="select_with_broadcast_table_and_single_table">
+        <input sql="SELECT * FROM t_single s INNER JOIN t_config c ON 
s.account_id = c.account_id" />
+        <output sql="SELECT * FROM t_single s INNER JOIN t_config c ON 
s.account_id = c.account_id" />
+    </rewrite-assertion>
 </rewrite-assertions>

Reply via email to