You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "morrySnow (via GitHub)" <gi...@apache.org> on 2023/06/05 04:24:28 UTC

[GitHub] [doris] morrySnow commented on a diff in pull request #20313: [Feature](Nereids)support update.

morrySnow commented on code in PR #20313:
URL: https://github.com/apache/doris/pull/20313#discussion_r1217439283


##########
fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4:
##########
@@ -525,6 +538,7 @@ nonReserved
     | DATE_DIFF
     | DAY
     | DBPROPERTIES
+    | DEFAULT

Review Comment:
   default is not in non reserved list in legacy planer



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java:
##########
@@ -2221,6 +2222,11 @@ private PlanFragment exchangeToMergeFragment(PlanFragment inputFragment, PlanTra
         PlanFragment fragment = new PlanFragment(context.nextFragmentId(), mergePlan, dataPartition);
         inputFragment.setDestination(mergePlan);
         context.addPlanFragment(fragment);
+        if (inputFragment.getSink() instanceof OlapTableSink) {
+            DataSink sink = inputFragment.getSink();
+            inputFragment.cleanSink();
+            fragment.setSink(sink);
+        }

Review Comment:
   ? why add this again?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UpdateCommand.java:
##########
@@ -0,0 +1,152 @@
+// 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.doris.nereids.trees.plans.commands;
+
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.KeysType;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.catalog.TableIf;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.Pair;
+import org.apache.doris.nereids.analyzer.UnboundOlapTableSink;
+import org.apache.doris.nereids.analyzer.UnboundSlot;
+import org.apache.doris.nereids.trees.expressions.Alias;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
+import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+import org.apache.doris.nereids.util.RelationUtil;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.SessionVariable;
+import org.apache.doris.qe.StmtExecutor;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * update command
+ * the two case will be handled as:
+ * case 1:
+ *  update table t1 set v1 = v1 + 1 where k1 = 1 and k2 = 2;
+ * =>
+ *  insert into table (v1) select v1 + 1 from table t1 where k1 = 1 and k2 = 2
+ * case 2:
+ *  update t1 set t1.c1 = t2.c1, t1.c3 = t2.c3 * 100
+ *  from t2 inner join t3 on t2.id = t3.id
+ *  where t1.id = t2.id;
+ * =>
+ *  insert into t1 (c1, c3) select t2.c1, t2.c3 * 100 from t1 join t2 inner join t3 on t2.id = t3.id where t1.id = t2.id
+ */
+public class UpdateCommand extends Command implements ForwardWithSync {
+    private final List<Pair<List<String>, Expression>> assignments;
+    private final List<String> nameParts;
+    private final String tableAlias;
+    private LogicalPlan logicalQuery;
+    private OlapTable targetTable;
+    private ExplainLevel explainLevel = null;
+
+    public UpdateCommand(List<String> nameParts, String tableAlias, List<Pair<List<String>, Expression>> assignments,
+            LogicalPlan logicalQuery) {
+        super(PlanType.UPDATE_COMMAND);
+        this.nameParts = nameParts;
+        this.tableAlias = tableAlias;
+        this.assignments = assignments;
+        this.logicalQuery = logicalQuery;
+    }
+
+    @Override
+    public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {
+        getQueryPlan(ctx);
+
+        if (explainLevel != null) {
+            new ExplainCommand(explainLevel, logicalQuery).run(ctx, executor);
+        } else {
+            new InsertIntoTableCommand(logicalQuery, null).run(ctx, executor);
+        }
+    }
+
+    /**
+     * public for test
+     */
+    public void getQueryPlan(ConnectContext ctx) throws AnalysisException {

Review Comment:
   if ur function named getXX, u must have a XX object as return value. please change this function name



##########
regression-test/suites/nereids_p0/update/update_unique_table.groovy:
##########
@@ -0,0 +1,39 @@
+// 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.
+
+suite('update_unique_table') {
+    sql 'use nereids_update_test'

Review Comment:
   why need to change database?



##########
regression-test/suites/nereids_p0/update/update_unique_table.groovy:
##########
@@ -0,0 +1,39 @@
+// 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.
+
+suite('update_unique_table') {
+    sql 'use nereids_update_test'
+    sql 'set enable_nereids_planner=true'
+    sql 'set enable_fallback_to_original_planner=false'
+    sql 'set enable_nereids_dml=true'
+    sql 'set parallel_fragment_exec_instance_num=13'
+
+    qt_sql 'select * from t1 order by id'
+
+    sql 'update t1 set c1 = c1 + 1, c3 = c2 * 2 where id = 1'
+
+    qt_sql 'select * from t1 order by id'
+
+    sql '''

Review Comment:
   add a case with simple update, such as `update a set c1 = 5 where id = 3`



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UpdateCommand.java:
##########
@@ -0,0 +1,152 @@
+// 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.doris.nereids.trees.plans.commands;
+
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.KeysType;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.catalog.TableIf;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.Pair;
+import org.apache.doris.nereids.analyzer.UnboundOlapTableSink;
+import org.apache.doris.nereids.analyzer.UnboundSlot;
+import org.apache.doris.nereids.trees.expressions.Alias;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
+import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+import org.apache.doris.nereids.util.RelationUtil;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.SessionVariable;
+import org.apache.doris.qe.StmtExecutor;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * update command
+ * the two case will be handled as:
+ * case 1:
+ *  update table t1 set v1 = v1 + 1 where k1 = 1 and k2 = 2;
+ * =>
+ *  insert into table (v1) select v1 + 1 from table t1 where k1 = 1 and k2 = 2
+ * case 2:
+ *  update t1 set t1.c1 = t2.c1, t1.c3 = t2.c3 * 100
+ *  from t2 inner join t3 on t2.id = t3.id
+ *  where t1.id = t2.id;
+ * =>
+ *  insert into t1 (c1, c3) select t2.c1, t2.c3 * 100 from t1 join t2 inner join t3 on t2.id = t3.id where t1.id = t2.id
+ */
+public class UpdateCommand extends Command implements ForwardWithSync {
+    private final List<Pair<List<String>, Expression>> assignments;
+    private final List<String> nameParts;
+    private final String tableAlias;
+    private LogicalPlan logicalQuery;
+    private OlapTable targetTable;
+    private ExplainLevel explainLevel = null;
+
+    public UpdateCommand(List<String> nameParts, String tableAlias, List<Pair<List<String>, Expression>> assignments,
+            LogicalPlan logicalQuery) {
+        super(PlanType.UPDATE_COMMAND);
+        this.nameParts = nameParts;
+        this.tableAlias = tableAlias;
+        this.assignments = assignments;
+        this.logicalQuery = logicalQuery;
+    }
+
+    @Override
+    public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {
+        getQueryPlan(ctx);
+
+        if (explainLevel != null) {
+            new ExplainCommand(explainLevel, logicalQuery).run(ctx, executor);
+        } else {
+            new InsertIntoTableCommand(logicalQuery, null).run(ctx, executor);
+        }
+    }
+
+    /**
+     * public for test
+     */
+    public void getQueryPlan(ConnectContext ctx) throws AnalysisException {
+        checkTable(ctx);
+
+        if (logicalQuery instanceof ExplainCommand) {
+            explainLevel = ((ExplainCommand) logicalQuery).getLevel();
+            logicalQuery = ((ExplainCommand) logicalQuery).getLogicalPlan();
+        }
+
+        Map<String, Expression> colNameToExpression = Maps.newHashMap();
+        for (Pair<List<String>, Expression> pair : assignments) {
+            colNameToExpression.put(pair.first.get(pair.first.size() - 1), pair.second);
+        }
+        List<NamedExpression> selectLists = Lists.newArrayList();

Review Comment:
   ```suggestion
           List<NamedExpression> selectItems = Lists.newArrayList();
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -1318,6 +1342,18 @@ public List<String> visitIdentifierSeq(IdentifierSeqContext ctx) {
             .collect(ImmutableList.toImmutableList());
     }
 
+    @Override
+    public Pair<List<String>, Expression> visitUpdateAssignment(UpdateAssignmentContext ctx) {
+        return Pair.of(visitMultipartIdentifier(ctx.multipartIdentifier()), getExpression(ctx.expression()));
+    }

Review Comment:
   why not gernate `Equals(unboundSlot, Expression)`



##########
regression-test/suites/nereids_p0/update/update_unique_table.groovy:
##########
@@ -0,0 +1,39 @@
+// 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.
+
+suite('update_unique_table') {
+    sql 'use nereids_update_test'
+    sql 'set enable_nereids_planner=true'
+    sql 'set enable_fallback_to_original_planner=false'
+    sql 'set enable_nereids_dml=true'
+    sql 'set parallel_fragment_exec_instance_num=13'

Review Comment:
   remove set parallel_fragment_exec_instance_num=13



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/InsertIntoTableCommand.java:
##########
@@ -76,7 +76,7 @@ public NereidsPlanner getPlanner() {
 
     @Override
     public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {
-        if (!ctx.getSessionVariable().isEnableNereidsDML()) {
+        if (false && !ctx.getSessionVariable().isEnableNereidsDML()) {

Review Comment:
   ??



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/PlanVisitor.java:
##########
@@ -128,6 +129,10 @@ public R visitInsertIntoCommand(InsertIntoTableCommand insertIntoSelectCommand,
         return visit(insertIntoSelectCommand, context);
     }
 
+    public R visitUpdateCommand(UpdateCommand updateCommand, C context) {
+        return visit(updateCommand, context);
+    }
+

Review Comment:
   like what do on sclarFunction and agg function in expression vistor, move all command visitor into another file



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UpdateCommand.java:
##########
@@ -0,0 +1,152 @@
+// 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.doris.nereids.trees.plans.commands;
+
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.KeysType;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.catalog.TableIf;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.Pair;
+import org.apache.doris.nereids.analyzer.UnboundOlapTableSink;
+import org.apache.doris.nereids.analyzer.UnboundSlot;
+import org.apache.doris.nereids.trees.expressions.Alias;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
+import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+import org.apache.doris.nereids.util.RelationUtil;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.SessionVariable;
+import org.apache.doris.qe.StmtExecutor;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * update command
+ * the two case will be handled as:
+ * case 1:
+ *  update table t1 set v1 = v1 + 1 where k1 = 1 and k2 = 2;
+ * =>
+ *  insert into table (v1) select v1 + 1 from table t1 where k1 = 1 and k2 = 2
+ * case 2:
+ *  update t1 set t1.c1 = t2.c1, t1.c3 = t2.c3 * 100
+ *  from t2 inner join t3 on t2.id = t3.id
+ *  where t1.id = t2.id;
+ * =>
+ *  insert into t1 (c1, c3) select t2.c1, t2.c3 * 100 from t1 join t2 inner join t3 on t2.id = t3.id where t1.id = t2.id
+ */
+public class UpdateCommand extends Command implements ForwardWithSync {
+    private final List<Pair<List<String>, Expression>> assignments;
+    private final List<String> nameParts;
+    private final String tableAlias;
+    private LogicalPlan logicalQuery;
+    private OlapTable targetTable;
+    private ExplainLevel explainLevel = null;
+
+    public UpdateCommand(List<String> nameParts, String tableAlias, List<Pair<List<String>, Expression>> assignments,
+            LogicalPlan logicalQuery) {
+        super(PlanType.UPDATE_COMMAND);
+        this.nameParts = nameParts;
+        this.tableAlias = tableAlias;
+        this.assignments = assignments;
+        this.logicalQuery = logicalQuery;
+    }
+
+    @Override
+    public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {
+        getQueryPlan(ctx);
+
+        if (explainLevel != null) {
+            new ExplainCommand(explainLevel, logicalQuery).run(ctx, executor);
+        } else {
+            new InsertIntoTableCommand(logicalQuery, null).run(ctx, executor);
+        }
+    }
+
+    /**
+     * public for test
+     */
+    public void getQueryPlan(ConnectContext ctx) throws AnalysisException {
+        checkTable(ctx);
+
+        if (logicalQuery instanceof ExplainCommand) {
+            explainLevel = ((ExplainCommand) logicalQuery).getLevel();
+            logicalQuery = ((ExplainCommand) logicalQuery).getLogicalPlan();
+        }

Review Comment:
   same problem with insert, if user write `explain update xxx`, u should generate a ExplainCommand other than UpdateCommand



##########
regression-test/suites/nereids_p0/update/load.groovy:
##########
@@ -0,0 +1,85 @@
+// 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.
+
+suite("load") {

Review Comment:
   why add this case?



##########
fe/fe-core/src/main/java/org/apache/doris/planner/PlanFragment.java:
##########
@@ -390,6 +390,10 @@ public DataSink getSink() {
         return sink;
     }
 
+    public void cleanSink() {
+        this.sink = null;
+    }
+

Review Comment:
   why need this?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UpdateCommand.java:
##########
@@ -0,0 +1,152 @@
+// 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.doris.nereids.trees.plans.commands;
+
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.KeysType;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.catalog.TableIf;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.Pair;
+import org.apache.doris.nereids.analyzer.UnboundOlapTableSink;
+import org.apache.doris.nereids.analyzer.UnboundSlot;
+import org.apache.doris.nereids.trees.expressions.Alias;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
+import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+import org.apache.doris.nereids.util.RelationUtil;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.SessionVariable;
+import org.apache.doris.qe.StmtExecutor;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * update command
+ * the two case will be handled as:
+ * case 1:
+ *  update table t1 set v1 = v1 + 1 where k1 = 1 and k2 = 2;
+ * =>
+ *  insert into table (v1) select v1 + 1 from table t1 where k1 = 1 and k2 = 2
+ * case 2:
+ *  update t1 set t1.c1 = t2.c1, t1.c3 = t2.c3 * 100
+ *  from t2 inner join t3 on t2.id = t3.id
+ *  where t1.id = t2.id;
+ * =>
+ *  insert into t1 (c1, c3) select t2.c1, t2.c3 * 100 from t1 join t2 inner join t3 on t2.id = t3.id where t1.id = t2.id
+ */
+public class UpdateCommand extends Command implements ForwardWithSync {
+    private final List<Pair<List<String>, Expression>> assignments;
+    private final List<String> nameParts;
+    private final String tableAlias;
+    private LogicalPlan logicalQuery;
+    private OlapTable targetTable;
+    private ExplainLevel explainLevel = null;
+
+    public UpdateCommand(List<String> nameParts, String tableAlias, List<Pair<List<String>, Expression>> assignments,
+            LogicalPlan logicalQuery) {
+        super(PlanType.UPDATE_COMMAND);
+        this.nameParts = nameParts;
+        this.tableAlias = tableAlias;
+        this.assignments = assignments;
+        this.logicalQuery = logicalQuery;

Review Comment:
   1. ImmutableXXX.copyOf
   2. require non null



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UpdateCommand.java:
##########
@@ -0,0 +1,152 @@
+// 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.doris.nereids.trees.plans.commands;
+
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.KeysType;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.catalog.TableIf;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.Pair;
+import org.apache.doris.nereids.analyzer.UnboundOlapTableSink;
+import org.apache.doris.nereids.analyzer.UnboundSlot;
+import org.apache.doris.nereids.trees.expressions.Alias;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
+import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+import org.apache.doris.nereids.util.RelationUtil;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.SessionVariable;
+import org.apache.doris.qe.StmtExecutor;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * update command
+ * the two case will be handled as:
+ * case 1:
+ *  update table t1 set v1 = v1 + 1 where k1 = 1 and k2 = 2;
+ * =>
+ *  insert into table (v1) select v1 + 1 from table t1 where k1 = 1 and k2 = 2
+ * case 2:
+ *  update t1 set t1.c1 = t2.c1, t1.c3 = t2.c3 * 100
+ *  from t2 inner join t3 on t2.id = t3.id
+ *  where t1.id = t2.id;
+ * =>
+ *  insert into t1 (c1, c3) select t2.c1, t2.c3 * 100 from t1 join t2 inner join t3 on t2.id = t3.id where t1.id = t2.id
+ */
+public class UpdateCommand extends Command implements ForwardWithSync {
+    private final List<Pair<List<String>, Expression>> assignments;
+    private final List<String> nameParts;
+    private final String tableAlias;
+    private LogicalPlan logicalQuery;
+    private OlapTable targetTable;
+    private ExplainLevel explainLevel = null;
+
+    public UpdateCommand(List<String> nameParts, String tableAlias, List<Pair<List<String>, Expression>> assignments,
+            LogicalPlan logicalQuery) {
+        super(PlanType.UPDATE_COMMAND);
+        this.nameParts = nameParts;
+        this.tableAlias = tableAlias;
+        this.assignments = assignments;
+        this.logicalQuery = logicalQuery;
+    }
+
+    @Override
+    public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {
+        getQueryPlan(ctx);
+
+        if (explainLevel != null) {
+            new ExplainCommand(explainLevel, logicalQuery).run(ctx, executor);
+        } else {
+            new InsertIntoTableCommand(logicalQuery, null).run(ctx, executor);

Review Comment:
   could we do some abstract, not to new a InsertIntoTableCommand explicitly, but reuse some code between insert, update and delete?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -315,6 +319,26 @@ public LogicalPlan visitInsertIntoQuery(InsertIntoQueryContext ctx) {
         return new InsertIntoTableCommand(sink, labelName);
     }
 
+    @Override
+    public Object visitUpdate(UpdateContext ctx) {
+        LogicalPlan query = withCheckPolicy(new UnboundRelation(
+                RelationUtil.newRelationId(), visitMultipartIdentifier(ctx.tableName)));

Review Comment:
   why not process alias here with `withTableAlias`



-- 
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: commits-unsubscribe@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org