omkar-shitole commented on code in PR #34227:
URL: https://github.com/apache/shardingsphere/pull/34227#discussion_r1933243745


##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/insert/values/OnConflictUpdateContext.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.infra.binder.context.segment.insert.values;
+
+import com.google.common.base.Preconditions;
+import lombok.Getter;
+import 
org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor;
+import 
org.apache.shardingsphere.sql.parser.statement.core.extractor.ExpressionExtractor;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.ColumnAssignmentSegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.FunctionSegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * On conflict context.
+ */
+@Getter
+public final class OnConflictUpdateContext {
+    
+    private final int parameterCount;
+    
+    private final List<ExpressionSegment> valueExpressions;
+    
+    private final Collection<WhereSegment> whereSegments = new LinkedList<>();
+    
+    private final Collection<ColumnSegment> columnSegments;
+    
+    private final List<ParameterMarkerExpressionSegment> 
parameterMarkerExpressions;
+    
+    private final List<Object> parameters;
+    
+    public OnConflictUpdateContext(final Collection<ColumnAssignmentSegment> 
assignments, final List<Object> params, final int parametersOffset, final 
Optional<WhereSegment> segment) {
+        List<ExpressionSegment> expressionSegments = 
assignments.stream().map(ColumnAssignmentSegment::getValue).collect(Collectors.toList());
+        segment.ifPresent(whereSegments::add);
+        for (WhereSegment whereSegment : whereSegments) {
+            expressionSegments.add(whereSegment.getExpr());
+        }
+        columnSegments = assignments.stream().map(each -> 
each.getColumns().get(0)).collect(Collectors.toList());

Review Comment:
   Postgres ON CONFLICT clause only updates the specified conflicting column, 
and each assignment logically corresponds to a single column in this context.
   In Mysql, the same provision has been made considering only one column will 
be assigned per assignment.



-- 
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.

To unsubscribe, e-mail: notifications-unsubscr...@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to