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 56835d1531f Remove repetitive join condition judgement logic for sonar
issue (#26652)
56835d1531f is described below
commit 56835d1531f22c7012d7c67fc774c2f85efa285f
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Wed Jun 28 14:41:29 2023 +0800
Remove repetitive join condition judgement logic for sonar issue (#26652)
---
.../java/org/apache/shardingsphere/sharding/rule/ShardingRule.java | 5 +----
.../org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java | 2 ++
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
index 47d1eb84c12..6895ead1d7d 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
@@ -61,7 +61,6 @@ import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.Expressi
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.AndPredicate;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.util.ExpressionExtractUtils;
-import org.apache.shardingsphere.sql.parser.sql.common.util.WhereExtractUtils;
import java.util.Arrays;
import java.util.Collection;
@@ -447,9 +446,7 @@ public final class ShardingRule implements DatabaseRule,
DataNodeContainedRule,
String defaultSchemaName =
DatabaseTypeEngine.getDefaultSchemaName(sqlStatementContext.getDatabaseType(),
database.getName());
ShardingSphereSchema schema =
sqlStatementContext.getTablesContext().getSchemaName().map(database::getSchema).orElseGet(()
-> database.getSchema(defaultSchemaName));
SelectStatementContext select = (SelectStatementContext)
sqlStatementContext;
- Collection<WhereSegment> joinSegments =
WhereExtractUtils.getJoinWhereSegments(select.getSqlStatement());
- return isJoinConditionContainsShardingColumns(schema, select,
logicTableNames, joinSegments)
- || isJoinConditionContainsShardingColumns(schema, select,
logicTableNames, select.getWhereSegments());
+ return isJoinConditionContainsShardingColumns(schema, select,
logicTableNames, select.getWhereSegments());
}
private Optional<BindingTableRule> findBindingTableRule(final
Collection<String> logicTableNames) {
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
index bd586b46191..7060d9237a8 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
@@ -48,6 +48,7 @@ import
org.apache.shardingsphere.sharding.exception.metadata.ShardingTableRuleNo
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.JoinTableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
@@ -586,6 +587,7 @@ class ShardingRuleTest {
when(sqlStatementContext.isContainsJoinQuery()).thenReturn(true);
when(sqlStatementContext.getDatabaseType()).thenReturn(new
MySQLDatabaseType());
when(sqlStatementContext.getTablesContext().getSchemaName()).thenReturn(Optional.empty());
+
when(sqlStatementContext.getWhereSegments()).thenReturn(Collections.singletonList(new
WhereSegment(0, 0, condition)));
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(sqlStatementContext.getTablesContext().findTableNamesByColumnSegment(Arrays.asList(leftDatabaseJoin,
rightDatabaseJoin), schema)).thenReturn(createColumnTableNameMap());
when(sqlStatementContext.getTablesContext().findTableNamesByColumnSegment(Arrays.asList(leftTableJoin,
rightTableJoin), schema)).thenReturn(createColumnTableNameMap());