[fix](partial-update) insert only without auto_inc column should not use partial update (#38229) (#38504)
cherry-pick #38229 to branch-2.1 ## Proposed changes Issue Number: close #xxx <!--Describe your changes.-->
This commit is contained in:
@ -1309,6 +1309,7 @@ public class NativeInsertStmt extends InsertStmt {
|
||||
if (hasEmptyTargetColumns) {
|
||||
return;
|
||||
}
|
||||
boolean hasMissingColExceptAutoInc = false;
|
||||
for (Column col : olapTable.getFullSchema()) {
|
||||
boolean exists = false;
|
||||
for (Column insertCol : targetColumns) {
|
||||
@ -1321,10 +1322,18 @@ public class NativeInsertStmt extends InsertStmt {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (col.isKey() && !exists) {
|
||||
throw new UserException("Partial update should include all key columns, missing: " + col.getName());
|
||||
if (!exists && !col.isAutoInc()) {
|
||||
if (col.isKey()) {
|
||||
throw new UserException("Partial update should include all key columns, missing: " + col.getName());
|
||||
}
|
||||
if (col.isVisible()) {
|
||||
hasMissingColExceptAutoInc = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!hasMissingColExceptAutoInc) {
|
||||
return;
|
||||
}
|
||||
|
||||
isPartialUpdate = true;
|
||||
for (String name : targetColumnNames) {
|
||||
|
||||
@ -274,15 +274,24 @@ public class InsertUtils {
|
||||
} 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());
|
||||
((UnboundTableSink<? extends Plan>) unboundLogicalSink).setPartialUpdate(false);
|
||||
} else {
|
||||
boolean hasMissingColExceptAutoInc = false;
|
||||
for (Column col : olapTable.getFullSchema()) {
|
||||
Optional<String> insertCol = unboundLogicalSink.getColNames().stream()
|
||||
.filter(c -> c.equalsIgnoreCase(col.getName())).findFirst();
|
||||
if (!col.isAutoInc() && !insertCol.isPresent()) {
|
||||
if (col.isKey()) {
|
||||
throw new AnalysisException("Partial update should include all key columns,"
|
||||
+ " missing: " + col.getName());
|
||||
}
|
||||
if (col.isVisible()) {
|
||||
hasMissingColExceptAutoInc = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!hasMissingColExceptAutoInc) {
|
||||
((UnboundTableSink<? extends Plan>) unboundLogicalSink).setPartialUpdate(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user