suxiaogang223 commented on code in PR #66498: URL: https://github.com/apache/doris/pull/66498#discussion_r3772641867
########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/PaimonRowChangePlanBuilder.java: ########## @@ -0,0 +1,137 @@ +// 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.rules.analysis; + +import org.apache.doris.catalog.Column; +import org.apache.doris.common.util.Util; +import org.apache.doris.datasource.paimon.PaimonRowChangeOperation; +import org.apache.doris.datasource.paimon.PaimonWriteTarget; +import org.apache.doris.nereids.CascadesContext; +import org.apache.doris.nereids.analyzer.Scope; +import org.apache.doris.nereids.analyzer.UnboundSlot; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.nereids.trees.expressions.Alias; +import org.apache.doris.nereids.trees.expressions.EqualTo; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.NamedExpression; +import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral; +import org.apache.doris.nereids.trees.plans.commands.info.PaimonRowChangeSpec; +import org.apache.doris.nereids.trees.plans.logical.LogicalPlan; +import org.apache.doris.nereids.trees.plans.logical.LogicalProject; +import org.apache.doris.nereids.types.DataType; +import org.apache.doris.nereids.util.TypeCoercionUtils; + +import com.google.common.collect.Maps; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** Builds a Paimon changelog projection against the current write target. */ +final class PaimonRowChangePlanBuilder { + private PaimonRowChangePlanBuilder() { + } + + static LogicalProject<?> build( + PaimonWriteTarget target, PaimonRowChangeSpec spec, LogicalPlan child, + CascadesContext cascadesContext) { + PaimonRowChangeCapabilities.check(target, spec, cascadesContext); + if (spec instanceof PaimonRowChangeSpec.Update) { + return buildUpdate(target, (PaimonRowChangeSpec.Update) spec, + child, cascadesContext); + } + if (spec instanceof PaimonRowChangeSpec.Delete) { + return buildDelete(target, (PaimonRowChangeSpec.Delete) spec, + child, cascadesContext); + } + if (spec instanceof PaimonRowChangeSpec.Merge) { + return PaimonMergePlanner.build(target, (PaimonRowChangeSpec.Merge) spec, + child, cascadesContext); + } + throw new AnalysisException("Unsupported Paimon row-change specification: " + + spec.getClass().getSimpleName()); + } + + private static LogicalProject<?> buildUpdate(PaimonWriteTarget target, + PaimonRowChangeSpec.Update update, LogicalPlan child, + CascadesContext cascadesContext) { + Map<String, Expression> changes = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER); + for (EqualTo assignment : update.getAssignments()) { + List<String> parts = ((UnboundSlot) assignment.left()).getNameParts(); + String columnName = parts.get(parts.size() - 1); + if (changes.put(columnName, assignment.right()) != null) { + throw new AnalysisException( + "Duplicate column name in Paimon UPDATE: " + columnName); + } + } + + String targetName = update.getTableAlias() != null + ? update.getTableAlias() + : Util.getTempTableDisplayName(target.getDorisTable().getName()); Review Comment: Addressed in 8ff74c6abe. Paimon row-change specs now carry the resolved full target qualifier, or the explicit alias, and synthesized target row-image slots use that identity directly. Added same-basename UPDATE FROM, MERGE, and DELETE USING regressions. FE Debug build passed. ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromUsingCommand.java: ########## @@ -55,6 +58,17 @@ public void run(ConnectContext ctx, StmtExecutor executor) throws Exception { + " Please check the following session variables: " + ctx.getSessionVariable().printDebugModeVariables()); } + TableIf table = RelationUtil.getTable(RelationUtil.getQualifierName(ctx, nameParts), + ctx.getEnv(), Optional.empty()); + if (table instanceof PaimonExternalTable) { + if (isTempPart || !partitions.isEmpty()) { + throw new AnalysisException( + "Paimon DELETE does not support partition name lists; use a WHERE predicate"); + } + new PaimonDeleteCommand(nameParts, tableAlias, handleCte(logicalQuery)) Review Comment: Addressed in 8ff74c6abe. Paimon DELETE row images now use a distinct project, which the normal analysis pipeline lowers to an aggregate before sink binding, so duplicate USING matches emit one DELETE per target row. Added an incremental audit-log regression with duplicate source matches. FE Debug build passed. ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromUsingCommand.java: ########## @@ -55,6 +58,17 @@ public void run(ConnectContext ctx, StmtExecutor executor) throws Exception { + " Please check the following session variables: " + ctx.getSessionVariable().printDebugModeVariables()); } + TableIf table = RelationUtil.getTable(RelationUtil.getQualifierName(ctx, nameParts), + ctx.getEnv(), Optional.empty()); + if (table instanceof PaimonExternalTable) { + if (isTempPart || !partitions.isEmpty()) { + throw new AnalysisException( + "Paimon DELETE does not support partition name lists; use a WHERE predicate"); + } + new PaimonDeleteCommand(nameParts, tableAlias, handleCte(logicalQuery)) Review Comment: Addressed in 8ff74c6abe. Paimon DELETE row images now use a distinct project, which the normal analysis pipeline lowers to an aggregate before sink binding, so duplicate USING matches emit one DELETE per target row. Added an incremental audit-log regression with duplicate source matches. FE Debug build passed. ########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/PaimonRowChangePlanBuilder.java: ########## @@ -0,0 +1,137 @@ +// 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.rules.analysis; + +import org.apache.doris.catalog.Column; +import org.apache.doris.common.util.Util; +import org.apache.doris.datasource.paimon.PaimonRowChangeOperation; +import org.apache.doris.datasource.paimon.PaimonWriteTarget; +import org.apache.doris.nereids.CascadesContext; +import org.apache.doris.nereids.analyzer.Scope; +import org.apache.doris.nereids.analyzer.UnboundSlot; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.nereids.trees.expressions.Alias; +import org.apache.doris.nereids.trees.expressions.EqualTo; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.NamedExpression; +import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral; +import org.apache.doris.nereids.trees.plans.commands.info.PaimonRowChangeSpec; +import org.apache.doris.nereids.trees.plans.logical.LogicalPlan; +import org.apache.doris.nereids.trees.plans.logical.LogicalProject; +import org.apache.doris.nereids.types.DataType; +import org.apache.doris.nereids.util.TypeCoercionUtils; + +import com.google.common.collect.Maps; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** Builds a Paimon changelog projection against the current write target. */ +final class PaimonRowChangePlanBuilder { + private PaimonRowChangePlanBuilder() { + } + + static LogicalProject<?> build( + PaimonWriteTarget target, PaimonRowChangeSpec spec, LogicalPlan child, + CascadesContext cascadesContext) { + PaimonRowChangeCapabilities.check(target, spec, cascadesContext); + if (spec instanceof PaimonRowChangeSpec.Update) { + return buildUpdate(target, (PaimonRowChangeSpec.Update) spec, + child, cascadesContext); + } + if (spec instanceof PaimonRowChangeSpec.Delete) { + return buildDelete(target, (PaimonRowChangeSpec.Delete) spec, + child, cascadesContext); + } + if (spec instanceof PaimonRowChangeSpec.Merge) { + return PaimonMergePlanner.build(target, (PaimonRowChangeSpec.Merge) spec, + child, cascadesContext); + } + throw new AnalysisException("Unsupported Paimon row-change specification: " + + spec.getClass().getSimpleName()); + } + + private static LogicalProject<?> buildUpdate(PaimonWriteTarget target, + PaimonRowChangeSpec.Update update, LogicalPlan child, + CascadesContext cascadesContext) { + Map<String, Expression> changes = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER); + for (EqualTo assignment : update.getAssignments()) { + List<String> parts = ((UnboundSlot) assignment.left()).getNameParts(); + String columnName = parts.get(parts.size() - 1); + if (changes.put(columnName, assignment.right()) != null) { + throw new AnalysisException( + "Duplicate column name in Paimon UPDATE: " + columnName); + } + } + + String targetName = update.getTableAlias() != null + ? update.getTableAlias() + : Util.getTempTableDisplayName(target.getDorisTable().getName()); Review Comment: Addressed in 8ff74c6abe. Paimon row-change specs now carry the resolved full target qualifier, or the explicit alias, and synthesized target row-image slots use that identity directly. Added same-basename UPDATE FROM, MERGE, and DELETE USING regressions. FE Debug build passed. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
