From 2ebf871c0cba67ff5d2dad44a6d996f2bbb06158 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 26 Jan 2025 20:24:32 +0800 Subject: [PATCH] branch-3.0 [fix](delete) fix insert into cols should be corresponding to the query output for delete from command #47406 (#47454) Cherry-picked from #47406 Co-authored-by: meiyi --- .../plans/commands/DeleteFromCommand.java | 3 +- .../delete/delete_mow_partial_update.out | 7 +++ .../delete/delete_mow_partial_update.groovy | 45 +++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromCommand.java index 34a54ec2651f65..8cc5135af863f2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromCommand.java @@ -408,7 +408,8 @@ public LogicalPlan completeQueryPlan(ConnectContext ctx, LogicalPlan logicalQuer expr = new UnboundAlias(new TinyIntLiteral(((byte) 1)), Column.DELETE_SIGN); } else if (column.getName().equalsIgnoreCase(Column.SEQUENCE_COL) && targetTable.getSequenceMapCol() != null) { - expr = new UnboundSlot(tableName, targetTable.getSequenceMapCol()); + expr = new UnboundAlias(new UnboundSlot(tableName, targetTable.getSequenceMapCol()), + Column.SEQUENCE_COL); } else if (column.isKey()) { expr = new UnboundSlot(tableName, column.getName()); } else if (!isMow && (!column.isVisible() || (!column.isAllowNull() && !column.hasDefaultValue()))) { diff --git a/regression-test/data/nereids_p0/delete/delete_mow_partial_update.out b/regression-test/data/nereids_p0/delete/delete_mow_partial_update.out index 54b9aa4cee9bae..1a090023156eac 100644 --- a/regression-test/data/nereids_p0/delete/delete_mow_partial_update.out +++ b/regression-test/data/nereids_p0/delete/delete_mow_partial_update.out @@ -103,3 +103,10 @@ 4 4 4 4 4 0 5 5 5 5 5 0 +-- !sql -- +2023-12-09 1 2 3 4 5.50 6.50 7.50 8.50 o k 2023-12-09 2023-12-10 a b yyyyyyyyy +2023-12-09 2 2 3 4 5.50 6.50 7.50 8.50 o k 2023-12-09 2023-12-10 a b yyyyyyyyy + +-- !sql -- +2023-12-09 1 2 3 4 5.50 6.50 7.50 8.50 o k 2023-12-09 2023-12-10 a b yyyyyyyyy + diff --git a/regression-test/suites/nereids_p0/delete/delete_mow_partial_update.groovy b/regression-test/suites/nereids_p0/delete/delete_mow_partial_update.groovy index a03a9a92fa746e..680b26a4e4ab38 100644 --- a/regression-test/suites/nereids_p0/delete/delete_mow_partial_update.groovy +++ b/regression-test/suites/nereids_p0/delete/delete_mow_partial_update.groovy @@ -146,4 +146,49 @@ suite('nereids_delete_mow_partial_update') { sql "drop table if exists ${tableName3};" } } + + def tableName = "nereids_delete_mow_partial_update10" + sql "DROP TABLE IF EXISTS ${tableName};" + sql """ + CREATE TABLE ${tableName} ( + `l_shipdate` date NOT NULL, + `l_orderkey` bigint NOT NULL, + `l_linenumber` bigint NOT NULL, + `l_partkey` bigint NOT NULL, + `l_suppkey` bigint NOT NULL, + `l_quantity` decimal(15,2) NOT NULL, + `l_extendedprice` decimal(15,2) NOT NULL, + `l_discount` decimal(15,2) NOT NULL, + `l_tax` decimal(15,2) NOT NULL, + `l_returnflag` varchar(1) NOT NULL, + `l_linestatus` varchar(1) NOT NULL, + `l_commitdate` date NOT NULL, + `l_receiptdate` date NOT NULL, + `l_shipinstruct` varchar(25) NOT NULL, + `l_shipmode` varchar(10) NOT NULL, + `l_comment` varchar(44) NOT NULL + ) + UNIQUE KEY(`l_shipdate`, `l_orderkey`, `l_linenumber`, `l_partkey`, `l_suppkey`) + DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "enable_unique_key_merge_on_write" = "true", + "function_column.sequence_col" = "l_Shipdate" + ); + """ + sql """ + insert into ${tableName} values + ('2023-12-09', 1, 2, 3, 4, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-12-09', '2023-12-10', 'a', 'b', 'yyyyyyyyy'), + ('2023-12-09', 2, 2, 3, 4, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-12-09', '2023-12-10', 'a', 'b', 'yyyyyyyyy') ; + """ + explain { + sql """ delete from ${tableName} where l_orderkey = 800; """ + contains "IS_PARTIAL_UPDATE: true" + } + sql """ delete from ${tableName} where l_orderkey = 800; """ + sql "sync" + order_qt_sql """ SELECT * FROM ${tableName}; """ + sql """ delete from ${tableName} where l_orderkey = 2; """ + sql "sync" + order_qt_sql """ SELECT * FROM ${tableName}; """ }