terrymanu commented on a change in pull request #3205: bugfix for #3144
URL: 
https://github.com/apache/incubator-shardingsphere/pull/3205#discussion_r333373522
 
 

 ##########
 File path: 
sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/router/sharding/validator/impl/ShardingUpdateStatementValidator.java
 ##########
 @@ -1,43 +1,161 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.core.route.router.sharding.validator.impl;
-
-import org.apache.shardingsphere.core.exception.ShardingException;
-import org.apache.shardingsphere.core.optimize.segment.table.TablesContext;
-import 
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.AssignmentSegment;
-import org.apache.shardingsphere.core.parse.sql.statement.dml.UpdateStatement;
-import 
org.apache.shardingsphere.core.route.router.sharding.validator.ShardingStatementValidator;
-import org.apache.shardingsphere.core.rule.ShardingRule;
-
-/**
- * Sharding update statement validator.
- *
- * @author zhangliang
- */
-public final class ShardingUpdateStatementValidator implements 
ShardingStatementValidator<UpdateStatement> {
-    
-    @Override
-    public void validate(final ShardingRule shardingRule, final 
UpdateStatement sqlStatement) {
-        String tableName = new 
TablesContext(sqlStatement).getSingleTableName();
-        for (AssignmentSegment each : 
sqlStatement.getSetAssignment().getAssignments()) {
-            if (shardingRule.isShardingColumn(each.getColumn().getName(), 
tableName)) {
-                throw new ShardingException("Can not update sharding key, 
logic table: [%s], column: [%s].", tableName, each);
-            }
-        }
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.core.route.router.sharding.validator.impl;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.shardingsphere.core.exception.ShardingException;
+import org.apache.shardingsphere.core.optimize.segment.table.TablesContext;
+import 
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.AssignmentSegment;
+import 
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment;
+import 
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.LiteralExpressionSegment;
+import 
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
+import 
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.AndPredicate;
+import 
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.PredicateSegment;
+import 
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.WhereSegment;
+import 
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.value.PredicateCompareRightValue;
+import 
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.value.PredicateInRightValue;
+import 
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.value.PredicateRightValue;
+import org.apache.shardingsphere.core.parse.sql.statement.dml.UpdateStatement;
+import 
org.apache.shardingsphere.core.route.router.sharding.validator.ShardingStatementValidator;
+import org.apache.shardingsphere.core.rule.ShardingRule;
+
+import com.google.common.base.Optional;
+
+/**
+ * Sharding update statement validator.
+ *
+ * @author zhangliang
+ */
+public final class ShardingUpdateStatementValidator implements 
ShardingStatementValidator<UpdateStatement> {
+
+    private Object getShardingColumnWhereValue(final WhereSegment 
whereSegment, final List<Object> parameters, final String shardingColumn) {
+        if (null == whereSegment.getAndPredicates() || null == parameters) {
+            return null;
+        }
+        for (AndPredicate andPredicate : whereSegment.getAndPredicates()) {
+            if (null == andPredicate.getPredicates()) {
+                continue;
+            }
+            return getShardingColumnWhereValue(andPredicate, parameters, 
shardingColumn);
+        }
+        return null;
+    }
+
+    private Object getShardingColumnWhereValue(final AndPredicate 
andPredicate, final List<Object> parameters, final String shardingColumn) {
+        for (PredicateSegment preSeg : andPredicate.getPredicates()) {
 
 Review comment:
   Please name variable as `each` during loop

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to