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 9be7c967db9 broadcast table support update/delete limit (#19059)
9be7c967db9 is described below

commit 9be7c967db9eb979eae49cdcd2616165396834cc
Author: natehuang <[email protected]>
AuthorDate: Tue Jul 12 17:21:03 2022 +0800

    broadcast table support update/delete limit (#19059)
---
 .../validator/dml/impl/ShardingDeleteStatementValidator.java      | 3 ++-
 .../validator/dml/impl/ShardingUpdateStatementValidator.java      | 2 +-
 .../validator/dml/ShardingUpdateStatementValidatorTest.java       | 8 ++++++++
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingDeleteStatementValidator.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingDeleteStatementValidator.java
index deea6cef360..ed01cf37888 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingDeleteStatementValidator.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingDeleteStatementValidator.java
@@ -43,7 +43,8 @@ public final class ShardingDeleteStatementValidator extends 
ShardingDMLStatement
     @Override
     public void postValidate(final ShardingRule shardingRule, final 
SQLStatementContext<DeleteStatement> sqlStatementContext, final List<Object> 
parameters,
                              final ShardingSphereDatabase database, final 
ConfigurationProperties props, final RouteContext routeContext) {
-        if 
(DeleteStatementHandler.getLimitSegment(sqlStatementContext.getSqlStatement()).isPresent()
 && routeContext.getRouteUnits().size() > 1) {
+        if 
(!shardingRule.isBroadcastTable(sqlStatementContext.getTablesContext().getTableNames().iterator().next())
+                && 
DeleteStatementHandler.getLimitSegment(sqlStatementContext.getSqlStatement()).isPresent()
 && routeContext.getRouteUnits().size() > 1) {
             throw new ShardingSphereException("DELETE ... LIMIT can not 
support sharding route to multiple data nodes.");
         }
     }
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingUpdateStatementValidator.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingUpdateStatementValidator.java
index 80e48770c95..d6078a87f4b 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingUpdateStatementValidator.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingUpdateStatementValidator.java
@@ -53,7 +53,7 @@ public final class ShardingUpdateStatementValidator extends 
ShardingDMLStatement
         if (setAssignmentRouteContext.isPresent() && 
!isSameRouteContext(routeContext, setAssignmentRouteContext.get())) {
             throw new ShardingSphereException("Can not update sharding key 
since the updated value will change %s's data nodes.", tableName);
         }
-        if 
(UpdateStatementHandler.getLimitSegment(sqlStatementContext.getSqlStatement()).isPresent()
 && routeContext.getRouteUnits().size() > 1) {
+        if (!shardingRule.isBroadcastTable(tableName) && 
UpdateStatementHandler.getLimitSegment(sqlStatementContext.getSqlStatement()).isPresent()
 && routeContext.getRouteUnits().size() > 1) {
             throw new ShardingSphereException("UPDATE ... LIMIT can not 
support sharding route to multiple data nodes.");
         }
     }
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java
index 1f1e9738e27..481df623e9e 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java
@@ -105,6 +105,14 @@ public final class ShardingUpdateStatementValidatorTest {
                 Collections.emptyList(), mock(ShardingSphereDatabase.class), 
mock(ConfigurationProperties.class), createSingleRouteContext());
     }
     
+    @Test
+    public void assertPostValidateWhenTableNameIsBroadcastTable() {
+        mockShardingRuleForUpdateShardingColumn();
+        when(shardingRule.isBroadcastTable("user")).thenReturn(true);
+        new ShardingUpdateStatementValidator().postValidate(shardingRule, new 
UpdateStatementContext(createUpdateStatement()),
+                Collections.emptyList(), mock(ShardingSphereDatabase.class), 
mock(ConfigurationProperties.class), createSingleRouteContext());
+    }
+    
     @Test(expected = ShardingSphereException.class)
     public void 
assertPostValidateWhenUpdateShardingColumnWithDifferentRouteContext() {
         mockShardingRuleForUpdateShardingColumn();

Reply via email to