Skip to content

Commit

Permalink
[fix](partial update) only unique table with MOW insert with target c…
Browse files Browse the repository at this point in the history
…olumns can consider be a partial update

Signed-off-by: nextdreamblue <[email protected]>
  • Loading branch information
nextdreamblue committed Apr 15, 2024
1 parent 2f3b195 commit 24458b1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1285,12 +1285,16 @@ private void trySetPartialUpdate() throws UserException {
if (olapTable.getKeysType() != KeysType.UNIQUE_KEYS) {
return;
}
// 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.
// when enable_unique_key_partial_update = false,
// unique table with MOW, insert will be a normal insert, and column that not set will insert default value.
if (!olapTable.getEnableUniqueKeyMergeOnWrite()) {
throw new UserException("Partial update is only allowed on unique table with merge-on-write enabled.");
return;
}
if (hasEmptyTargetColumns) {
throw new AnalysisException("You must explicitly specify the columns to be updated when "
+ "updating partial columns using the INSERT statement.");
return;
}
for (Column col : olapTable.getFullSchema()) {
boolean exists = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,11 @@
10000 2017-10-01 2017-10-01T08:00:05 北京 20 0 2017-10-01T06:00 20 10 10
10000 2017-10-01 2017-10-01T09:00:05 北京 20 0 2017-10-01T07:00 15 2 2

-- !sql --
10000 2017-10-01 2017-10-01T08:00:05 北京 20 0 2017-10-01T06:00 20 10 10
10000 2017-10-01 2017-10-01T09:00:05 北京 20 0 2017-10-01T07:00 15 2 2

-- !sql --
10000 2017-10-01 2017-10-01T08:00:05 北京 20 0 2017-10-01T06:00 20 10 10
10000 2017-10-01 2017-10-01T09:00:05 北京 20 0 2017-10-01T07:00 15 2 2

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ suite("nereids_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;"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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;"
Expand Down Expand Up @@ -329,12 +329,10 @@ suite("test_partial_update_native_insert_stmt", "p0") {
DISTRIBUTED BY HASH(`user_id`) BUCKETS 1
PROPERTIES ("replication_allocation" = "tag.location.default: 1", "enable_unique_key_merge_on_write" = "false");"""

test {
sql """insert into ${tableName10} values
(10000,"2017-10-01","2017-10-01 08:00:05","北京",20,0,"2017-10-01 06:00:00",20,10,10),
(10000,"2017-10-01","2017-10-01 09:00:05","北京",20,0,"2017-10-01 07:00:00",15,2,2); """
exception "Partial update is only allowed on unique table with merge-on-write enabled"
}
sql """insert into ${tableName10} values
(10000,"2017-10-01","2017-10-01 08:00:05","北京",20,0,"2017-10-01 06:00:00",20,10,10),
(10000,"2017-10-01","2017-10-01 09:00:05","北京",20,0,"2017-10-01 07:00:00",15,2,2); """
qt_sql "select * from ${tableName10} order by user_id;"

sql """ DROP TABLE IF EXISTS ${tableName8}; """
sql """ DROP TABLE IF EXISTS ${tableName9}; """
Expand Down

0 comments on commit 24458b1

Please sign in to comment.