This is an automated email from the ASF dual-hosted git repository. zhangchen pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push: new deddac03402 [branch-2.0] pick "[Fix](merge-on-write) throw exception when the user don't specify the insert columns in insert statement for partial update #25437" deddac03402 is described below commit deddac0340221a863effa345548c3be032cbe3ca Author: bobhan1 <bh2444151...@outlook.com> AuthorDate: Tue Oct 17 16:45:07 2023 +0800 [branch-2.0] pick "[Fix](merge-on-write) throw exception when the user don't specify the insert columns in insert statement for partial update #25437" --- .../src/main/java/org/apache/doris/analysis/NativeInsertStmt.java | 5 +++++ .../java/org/apache/doris/nereids/rules/analysis/BindSink.java | 6 ++++++ .../suites/nereids_p0/insert_into_table/partial_update.groovy | 4 ++++ .../nereids_p0/insert_into_table/partial_update_complex.groovy | 7 ++++++- .../partial_update/test_partial_update_native_insert_stmt.groovy | 4 ++++ .../test_partial_update_native_insert_stmt_complex.groovy | 7 ++++++- 6 files changed, 31 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java index 8cd080d7ecf..06d8a55187f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java @@ -453,6 +453,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)) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java index 3aba375e13e..2454c635e13 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java @@ -73,6 +73,12 @@ public class BindSink implements AnalysisRuleFactory { LogicalPlan child = ((LogicalPlan) sink.child()); + 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, 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 6068bd093b1..699c7c600c5 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 @@ -43,6 +43,10 @@ suite("nereids_partial_update_native_insert_stmt", "p0") { // existing rows should be updated and new rows should be inserted with unmentioned columns filled with default or null value sql """insert into ${tableName}(id,score) values(2,400),(1,200),(4,400)""" 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." + } sql "set enable_unique_key_partial_update=false;" sql "sync;" sql """ DROP TABLE IF EXISTS ${tableName} """ 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 b1d8be2bff0..66e237ff89c 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 @@ -77,7 +77,12 @@ suite("nereids_partial_update_native_insert_stmt_complex", "p0") { from ${tbName2} inner join ${tbName3} on ${tbName2}.id = ${tbName3}.id; """ qt_complex_update """select * from ${tbName1} order by id;""" - + test { + 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." + } sql "truncate table ${tbName1};" sql "truncate table ${tbName2};" sql "truncate table ${tbName3};" 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 a5c0360b9d6..01e3846ac2b 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 @@ -44,6 +44,10 @@ suite("test_partial_update_native_insert_stmt", "p0") { // existing rows should be updated and new rows should be inserted with unmentioned columns filled with default or null value sql """insert into ${tableName}(id,score) values(2,400),(1,200),(4,400)""" 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." + } sql "set enable_unique_key_partial_update=false;" sql "sync;" sql """ DROP TABLE IF EXISTS ${tableName} """ 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 8070db512d7..8dac6e9120e 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 @@ -77,7 +77,12 @@ suite("test_partial_update_native_insert_stmt_complex", "p0") { from ${tbName2} inner join ${tbName3} on ${tbName2}.id = ${tbName3}.id; """ qt_complex_update """select * from ${tbName1} order by id;""" - + test { + 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." + } sql "truncate table ${tbName1};" sql "truncate table ${tbName2};" sql "truncate table ${tbName3};" --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org