This is an automated email from the ASF dual-hosted git repository. dataroaring pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 0e5173aa53c [Fix](partial-update) Fix partial update case introduced by #33656 (#34260) 0e5173aa53c is described below commit 0e5173aa53cd40a101ee3360729f6a43db462a67 Author: abmdocrt <yukang.lian2...@gmail.com> AuthorDate: Tue Apr 30 19:14:58 2024 +0800 [Fix](partial-update) Fix partial update case introduced by #33656 (#34260) --- .../doris/nereids/analyzer/UnboundTableSink.java | 6 +++- .../trees/plans/commands/insert/InsertUtils.java | 32 ++++++++++++---------- .../insert_into_table/partial_update.groovy | 2 +- .../partial_update_complex.groovy | 2 +- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundTableSink.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundTableSink.java index 8ecd417691d..23c58ba42fb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundTableSink.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundTableSink.java @@ -48,7 +48,7 @@ public class UnboundTableSink<CHILD_TYPE extends Plan> extends UnboundLogicalSin private final List<String> hints; private final boolean temporaryPartition; private final List<String> partitions; - private final boolean isPartialUpdate; + private boolean isPartialUpdate; private final DMLCommandType dmlCommandType; private final boolean autoDetectPartition; @@ -114,6 +114,10 @@ public class UnboundTableSink<CHILD_TYPE extends Plan> extends UnboundLogicalSin return isPartialUpdate; } + public void setPartialUpdate(boolean isPartialUpdate) { + this.isPartialUpdate = isPartialUpdate; + } + @Override public Plan withChildren(List<Plan> children) { Preconditions.checkArgument(children.size() == 1, "UnboundOlapTableSink only accepts one child"); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java index f0e7fab736c..ad974e9e7bc 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java @@ -247,21 +247,25 @@ public class InsertUtils { && ((UnboundTableSink<? extends Plan>) unboundLogicalSink).isPartialUpdate()) { // check the necessary conditions for partial updates OlapTable olapTable = (OlapTable) table; + if (!olapTable.getEnableUniqueKeyMergeOnWrite()) { - throw new AnalysisException("Partial update is only allowed on " - + "unique table with merge-on-write enabled."); - } - if (unboundLogicalSink.getDMLCommandType() == DMLCommandType.INSERT) { - if (unboundLogicalSink.getColNames().isEmpty()) { - throw new AnalysisException("You must explicitly specify the columns to be updated when " - + "updating partial columns using the INSERT statement."); - } - for (Column col : olapTable.getFullSchema()) { - Optional<String> insertCol = unboundLogicalSink.getColNames().stream() - .filter(c -> c.equalsIgnoreCase(col.getName())).findFirst(); - if (col.isKey() && !insertCol.isPresent()) { - throw new AnalysisException("Partial update should include all key columns, missing: " - + col.getName()); + // when enable_unique_key_partial_update = true, + // only unique table with MOW insert with target columns can consider be a partial update, + // and unique table without MOW, insert will be like a normal insert. + ((UnboundTableSink<? extends Plan>) unboundLogicalSink).setPartialUpdate(false); + } else { + if (unboundLogicalSink.getDMLCommandType() == DMLCommandType.INSERT) { + if (unboundLogicalSink.getColNames().isEmpty()) { + throw new AnalysisException("You must explicitly specify the columns to be updated when " + + "updating partial columns using the INSERT statement."); + } + for (Column col : olapTable.getFullSchema()) { + Optional<String> insertCol = unboundLogicalSink.getColNames().stream() + .filter(c -> c.equalsIgnoreCase(col.getName())).findFirst(); + if (col.isKey() && !insertCol.isPresent()) { + throw new AnalysisException("Partial update should include all key columns, missing: " + + col.getName()); + } } } } diff --git a/regression-test/suites/nereids_p0/insert_into_table/partial_update.groovy b/regression-test/suites/nereids_p0/insert_into_table/partial_update.groovy index fd2145a71ed..c734bcf1846 100644 --- a/regression-test/suites/nereids_p0/insert_into_table/partial_update.groovy +++ b/regression-test/suites/nereids_p0/insert_into_table/partial_update.groovy @@ -56,7 +56,7 @@ suite("nereids_partial_update_native_insert_stmt", "p0") { qt_1 """ select * from ${tableName} order by id; """ test { sql """insert into ${tableName} values(2,400),(1,200),(4,400)""" - exception "Column count doesn't match value count" + exception "You must explicitly specify the columns to be updated when updating partial columns using the INSERT statement." } sql "set enable_unique_key_partial_update=false;" sql "sync;" diff --git a/regression-test/suites/nereids_p0/insert_into_table/partial_update_complex.groovy b/regression-test/suites/nereids_p0/insert_into_table/partial_update_complex.groovy index 00e13176e47..537b812d01c 100644 --- a/regression-test/suites/nereids_p0/insert_into_table/partial_update_complex.groovy +++ b/regression-test/suites/nereids_p0/insert_into_table/partial_update_complex.groovy @@ -91,7 +91,7 @@ suite("nereids_partial_update_native_insert_stmt_complex", "p0") { sql """insert into ${tbName1} select ${tbName2}.id, ${tbName2}.c1, ${tbName2}.c3 * 100 from ${tbName2} inner join ${tbName3} on ${tbName2}.id = ${tbName3}.id; """ - exception "Column count doesn't match value count" + exception "You must explicitly specify the columns to be updated when updating partial columns using the INSERT statement" } sql "truncate table ${tbName1};" sql "truncate table ${tbName2};" --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org