[Fix](merge-on-write) throw exception when the user don't specify the insert columns in insert statement for partial update (#25437)

This commit is contained in:
bobhan1
2023-10-16 14:05:06 +08:00
committed by GitHub
parent e94fbe169e
commit f698f205d5
6 changed files with 31 additions and 2 deletions

View File

@ -507,6 +507,11 @@ public class NativeInsertStmt extends InsertStmt {
Set<String> mentionedColumns = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
List<String> realTargetColumnNames;
if (targetColumnNames == null) {
if (!isFromDeleteOrUpdateStmt
&& analyzer.getContext().getSessionVariable().isEnableUniqueKeyPartialUpdate()) {
throw new AnalysisException("You must explicitly specify the columns to be updated when "
+ "updating partial columns using the INSERT statement.");
}
// the mentioned columns are columns which are visible to user, so here we use
// getBaseSchema(), not getFullSchema()
for (Column col : targetTable.getBaseSchema(false)) {

View File

@ -81,6 +81,12 @@ public class BindSink implements AnalysisRuleFactory {
boolean isNeedSequenceCol = child.getOutput().stream()
.anyMatch(slot -> slot.getName().equals(Column.SEQUENCE_COL));
if (sink.getColNames().isEmpty() && sink.isFromNativeInsertStmt()
&& sink.isPartialUpdate()) {
throw new AnalysisException("You must explicitly specify the columns to be updated when "
+ "updating partial columns using the INSERT statement.");
}
LogicalOlapTableSink<?> boundSink = new LogicalOlapTableSink<>(
database,
table,