This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 20a6f2a6598 [Cherry-Pick](branch-2.1) Pick "Fix partial update case
introduced by #33656 (#34260)" (#34767)
20a6f2a6598 is described below
commit 20a6f2a659806d053ef1494e6840292b560de3ac
Author: abmdocrt <[email protected]>
AuthorDate: Mon May 13 17:00:04 2024 +0800
[Cherry-Pick](branch-2.1) Pick "Fix partial update case introduced by
#33656 (#34260)" (#34767)
---
.../doris/nereids/analyzer/UnboundTableSink.java | 6 +++-
.../trees/plans/commands/insert/InsertUtils.java | 32 ++++++++++++----------
.../test_partial_update_native_insert_stmt.groovy | 2 +-
...artial_update_native_insert_stmt_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/unique_with_mow_p0/partial_update/test_partial_update_native_insert_stmt.groovy
b/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_native_insert_stmt.groovy
index 18b7ffe6fc2..f5b7a937bcd 100644
---
a/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_native_insert_stmt.groovy
+++
b/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_native_insert_stmt.groovy
@@ -52,7 +52,7 @@ suite("test_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 "You must explicitly specify the columns to be
updated when updating partial columns using the INSERT statement"
+ exception "Column count doesn't match value count"
}
sql "set enable_unique_key_partial_update=false;"
sql "sync;"
diff --git
a/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_native_insert_stmt_complex.groovy
b/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_native_insert_stmt_complex.groovy
index 99158b66cd6..975f62a685f 100644
---
a/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_native_insert_stmt_complex.groovy
+++
b/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_native_insert_stmt_complex.groovy
@@ -89,7 +89,7 @@ suite("test_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 "You must explicitly specify the columns to be
updated when updating partial columns using the INSERT statement"
+ exception "Column count doesn't match value count"
}
sql "truncate table ${tbName1};"
sql "truncate table ${tbName2};"
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]