zhannngchen commented on code in PR #17639: URL: https://github.com/apache/doris/pull/17639#discussion_r1133415876
########## fe/fe-core/src/main/java/org/apache/doris/analysis/UpdateStmt.java: ########## @@ -17,101 +17,123 @@ package org.apache.doris.analysis; +import org.apache.doris.catalog.Column; import org.apache.doris.catalog.Database; import org.apache.doris.catalog.Env; import org.apache.doris.catalog.KeysType; import org.apache.doris.catalog.OlapTable; import org.apache.doris.catalog.Table; -import org.apache.doris.catalog.Type; import org.apache.doris.common.AnalysisException; import org.apache.doris.common.ErrorCode; import org.apache.doris.common.ErrorReport; import org.apache.doris.common.UserException; import org.apache.doris.common.util.Util; import org.apache.doris.mysql.privilege.PrivPredicate; import org.apache.doris.qe.ConnectContext; -import org.apache.doris.rewrite.ExprRewriter; import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; import java.util.List; import java.util.Set; import java.util.TreeSet; /** - * UPDATE is a DML statement that modifies rows in a table. + * UPDATE is a DML statement that modifies rows in a unique key olap table. * The current update syntax only supports updating the filtered data of a single table. - * + * <p> * UPDATE table_reference * SET assignment_list + * [from_clause] * [WHERE where_condition] - * - * value: - * {expr} - * - * assignment: - * col_name = value - * + * <p> * assignment_list: * assignment [, assignment] ... + * <p> + * assignment: + * col_name = value + * <p> + * value: + * {expr} */ public class UpdateStmt extends DdlStmt { - private TableName tableName; - private List<Expr> setExprs; - private Expr whereExpr; - - // After analyzed + private final TableName tableName; + private final List<BinaryPredicate> setExprs; + private final Expr whereExpr; + private final FromClause fromClause; + private InsertStmt insertStmt; private Table targetTable; - private TupleDescriptor srcTupleDesc; + List<SelectListItem> selectListItems = Lists.newArrayList(); + List<String> cols = Lists.newArrayList(); - public UpdateStmt(TableName tableName, List<Expr> setExprs, Expr whereExpr) { + public UpdateStmt(TableName tableName, List<BinaryPredicate> setExprs, FromClause fromClause, Expr whereExpr) { this.tableName = tableName; this.setExprs = setExprs; + this.fromClause = fromClause; this.whereExpr = whereExpr; - } - - public TableName getTableName() { - return tableName; - } - - public List<Expr> getSetExprs() { - return setExprs; - } - - public Expr getWhereExpr() { - return whereExpr; - } - public Table getTargetTable() { - return targetTable; } - public TupleDescriptor getSrcTupleDesc() { - return srcTupleDesc; + public InsertStmt getInsertStmt() { + return insertStmt; } @Override public void analyze(Analyzer analyzer) throws UserException { super.analyze(analyzer); analyzeTargetTable(analyzer); analyzeSetExprs(analyzer); - analyzeWhereExpr(analyzer); + constructInsertStmt(); + } + + private void constructInsertStmt() { + // not use origin from clause, because we need to mod it, and this action will affect toSql(). + FromClause fromUsedInInsert; + TableRef tableRef = new TableRef(tableName, null); + if (fromClause == null) { + fromUsedInInsert = new FromClause(Lists.newArrayList(tableRef)); Review Comment: If the data to update is read from the same table, we might need to consider the sequence column. We should read the hidden sequence column if it exists. -- 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-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org