This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 0a569fd2b36 Fix routing error when joining tables in uppercase (#30205)
0a569fd2b36 is described below
commit 0a569fd2b364159db469cdad2b3587117123f5e4
Author: LotusMoon <[email protected]>
AuthorDate: Tue Feb 20 17:08:34 2024 +0800
Fix routing error when joining tables in uppercase (#30205)
* Fix routing error when joining tables in uppercase
* Apply spotless check
* Get shardingValues from sharding conditions ignore case
---
.../engine/type/standard/ShardingStandardRoutingEngine.java | 5 +++--
.../type/complex/ShardingComplexRoutingEngineTest.java | 13 +++++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRoutingEngine.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRoutingEngine.java
index 65dc2d19d47..78d51d5a4ac 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRoutingEngine.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRoutingEngine.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.route.engine.type.standard;
+import com.cedarsoftware.util.CaseInsensitiveSet;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.datanode.DataNode;
@@ -235,8 +236,8 @@ public final class ShardingStandardRoutingEngine implements
ShardingRouteEngine
List<ShardingConditionValue> result = new
ArrayList<>(shardingColumns.size());
for (ShardingConditionValue each : shardingCondition.getValues()) {
Optional<BindingTableRule> bindingTableRule =
shardingRule.findBindingTableRule(each.getTableName());
- if ((logicTableName.equals(each.getTableName()) ||
bindingTableRule.isPresent() &&
bindingTableRule.get().hasLogicTable(logicTableName))
- && shardingColumns.contains(each.getColumnName())) {
+ if ((logicTableName.equalsIgnoreCase(each.getTableName()) ||
bindingTableRule.isPresent() &&
bindingTableRule.get().hasLogicTable(logicTableName))
+ && new
CaseInsensitiveSet<>(shardingColumns).contains(each.getColumnName())) {
result.add(each);
}
}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/complex/ShardingComplexRoutingEngineTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/complex/ShardingComplexRoutingEngineTest.java
index e42fd8fe939..aaa9af43e90 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/complex/ShardingComplexRoutingEngineTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/complex/ShardingComplexRoutingEngineTest.java
@@ -66,6 +66,19 @@ class ShardingComplexRoutingEngineTest {
assertThat(routeUnits.get(0).getTableMappers().iterator().next().getLogicName(),
is("t_order"));
}
+ @Test
+ void assertRoutingForShardingTableJoinWithUpperCase() {
+ ShardingComplexRoutingEngine complexRoutingEngine = new
ShardingComplexRoutingEngine(ShardingRoutingEngineFixtureBuilder.createShardingConditions("T_ORDER"),
+ mock(SQLStatementContext.class), new HintValueContext(), new
ConfigurationProperties(new Properties()), Arrays.asList("T_ORDER",
"T_CONFIG"));
+ RouteContext routeContext =
complexRoutingEngine.route(ShardingRoutingEngineFixtureBuilder.createBroadcastShardingRule());
+ List<RouteUnit> routeUnits = new
ArrayList<>(routeContext.getRouteUnits());
+ assertThat(routeContext.getRouteUnits().size(), is(1));
+ assertThat(routeUnits.get(0).getDataSourceMapper().getActualName(),
is("ds_1"));
+ assertThat(routeUnits.get(0).getTableMappers().size(), is(1));
+
assertThat(routeUnits.get(0).getTableMappers().iterator().next().getActualName(),
is("t_order_1"));
+
assertThat(routeUnits.get(0).getTableMappers().iterator().next().getLogicName(),
is("t_order"));
+ }
+
@Test
void assertRoutingForNonLogicTable() {
ShardingComplexRoutingEngine complexRoutingEngine = new
ShardingComplexRoutingEngine(ShardingRoutingEngineFixtureBuilder.createShardingConditions("t_order"),