[Cherry-Pick](branch-2.1) Pick "Fix partial update case introduced by #33656 (#34260)" (#34767)

This commit is contained in:
abmdocrt
2024-05-13 17:00:04 +08:00
committed by GitHub
parent 4150971e07
commit 20a6f2a659
4 changed files with 25 additions and 17 deletions

View File

@ -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");

View File

@ -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());
}
}
}
}