From 6537d988b9b7a0df41d21221c75daf8e7bf6a127 Mon Sep 17 00:00:00 2001 From: bobhan1 Date: Mon, 17 Mar 2025 15:57:12 +0800 Subject: [PATCH] [Fix](partial update) use correct default value for missing columns in partial update (#49066) related PR: https://github.com/apache/doris/pull/48625 In partial update, we should fill the columns which is not nullable and doesn't have user defined default value with its type's default value when the row's delete sign is marked. --- be/src/olap/base_tablet.cpp | 2 +- be/src/olap/partial_update_info.cpp | 2 +- .../test_partial_update_complex_type.out | 20 +++++++++++ .../test_partial_update_complex_type.groovy | 35 ++++++++++++++++--- 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/be/src/olap/base_tablet.cpp b/be/src/olap/base_tablet.cpp index 6d7d4d84c3db70..3105b9f3179eb3 100644 --- a/be/src/olap/base_tablet.cpp +++ b/be/src/olap/base_tablet.cpp @@ -1014,7 +1014,7 @@ Status BaseTablet::generate_new_block_for_partial_update( mutable_column.get()) ->insert_null_elements(1); } else { - mutable_column->insert_default(); + mutable_column->insert(rs_column.get_vec_type()->get_default()); } } else { mutable_column->insert_from( diff --git a/be/src/olap/partial_update_info.cpp b/be/src/olap/partial_update_info.cpp index 5ab08b012f158c..94dd4673f59850 100644 --- a/be/src/olap/partial_update_info.cpp +++ b/be/src/olap/partial_update_info.cpp @@ -339,7 +339,7 @@ Status PartialUpdateReadPlan::fill_missing_columns( // If the control flow reaches this branch, the column neither has default value // nor is nullable. It means that the row's delete sign is marked, and the value // columns are useless and won't be read. So we can just put arbitary values in the cells - missing_col->insert_default(); + missing_col->insert(tablet_column.get_vec_type()->get_default()); } // clang-format on } diff --git a/regression-test/data/unique_with_mow_p0/partial_update/test_partial_update_complex_type.out b/regression-test/data/unique_with_mow_p0/partial_update/test_partial_update_complex_type.out index ae7ed3b79b904f..6f6a385a359772 100644 --- a/regression-test/data/unique_with_mow_p0/partial_update/test_partial_update_complex_type.out +++ b/regression-test/data/unique_with_mow_p0/partial_update/test_partial_update_complex_type.out @@ -21,6 +21,16 @@ 4 \N \N [1, 2, 3, 4, 5] \N 6 \N \N [] {"a":1000000, "b":10000000} +-- !sql -- +3 doris3 {"jsonk3":456,"jsonk5":789} [600, 400] {"a":2, "b":7} {"cccc":10} 4 0 + +-- !sql -- +1 doris1 {"jsonk1":123,"jsonk2":456} [100, 200] {"a":1, "b":2} {"b":3} 3 0 +1 \N null [null] {"a":null, "b":null} {null:null} 5 1 +2 doris2 {"jsonk2":333,"jsonk4":444} [300, 400] {"a":3, "b":4} {"a":2} 2 0 +2 \N null [null] {"a":null, "b":null} {null:null} 5 1 +3 doris3 {"jsonk3":456,"jsonk5":789} [600, 400] {"a":2, "b":7} {"cccc":10} 4 0 + -- !update_varchar -- 1 apache doris {"jsonk1":123,"jsonk2":456} [100, 200] {"a":1, "b":2} 2 apache doris 2.0 {"jsonk3":333,"jsonk4":444} [300, 400] {"a":3, "b":4} @@ -43,3 +53,13 @@ 4 \N \N [1, 2, 3, 4, 5] \N 6 \N \N [] {"a":1000000, "b":10000000} +-- !sql -- +3 doris3 {"jsonk3":456,"jsonk5":789} [600, 400] {"a":2, "b":7} {"cccc":10} 4 0 + +-- !sql -- +1 doris1 {"jsonk1":123,"jsonk2":456} [100, 200] {"a":1, "b":2} {"b":3} 3 0 +1 \N null [null] {"a":null, "b":null} {null:null} 5 1 +2 doris2 {"jsonk2":333,"jsonk4":444} [300, 400] {"a":3, "b":4} {"a":2} 2 0 +2 \N null [null] {"a":null, "b":null} {null:null} 5 1 +3 doris3 {"jsonk3":456,"jsonk5":789} [600, 400] {"a":2, "b":7} {"cccc":10} 4 0 + diff --git a/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_complex_type.groovy b/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_complex_type.groovy index ebd32310fd2b45..fc3cb097080e8c 100644 --- a/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_complex_type.groovy +++ b/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_complex_type.groovy @@ -1,4 +1,3 @@ - // Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -32,7 +31,7 @@ suite("test_primary_key_partial_update_complex_type", "p0") { // 2. the combination of map type and row store may result in bugs, so we skip map type in temporary // // create table - sql """ DROP TABLE IF EXISTS ${tableName} """ + sql """ DROP TABLE IF EXISTS ${tableName} FORCE""" sql """ CREATE TABLE ${tableName} ( `id` int(11) NOT NULL COMMENT "用户 ID", `c_varchar` varchar(65533) NULL COMMENT "用户姓名", @@ -120,8 +119,36 @@ suite("test_primary_key_partial_update_complex_type", "p0") { select * from ${tableName} order by id; """ - // drop table - sql """ DROP TABLE IF EXISTS ${tableName} """ + // create table for NOT NULL tests + def tableName2 = "${tableName}_not_null" + sql """ DROP TABLE IF EXISTS ${tableName2} FORCE""" + sql """ CREATE TABLE ${tableName2} ( + `id` int(11) NOT NULL COMMENT "用户 ID", + `c_varchar` varchar(65533) NULL COMMENT "用户姓名", + `c_jsonb` JSONB NOT NULL, + `c_array` ARRAY NOT NULL, + `c_struct` STRUCT NOT NULL, + `c_map` MAP not null) + UNIQUE KEY(`id`) DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES("replication_num" = "1", "enable_unique_key_merge_on_write" = "true", + "store_row_column" = "${use_row_store}"); """ + + sql """insert into ${tableName2} values(2, "doris2", '{"jsonk2": 333, "jsonk4": 444}', [300, 400], {3, 4}, {'a': 2})""" + sql """insert into ${tableName2} values(1, "doris1", '{"jsonk1": 123, "jsonk2": 456}', [100, 200], {1, 2}, {'b': 3})""" + sql """insert into ${tableName2} values(3, "doris3", '{"jsonk3": 456, "jsonk5": 789}', [600, 400], {2, 7}, {'cccc': 10})""" + String sql1 = "delete from ${tableName2} where id<=2;" + explain { + sql sql1 + contains "IS_PARTIAL_UPDATE: true" + } + sql(sql1) + + qt_sql """ select *,__DORIS_VERSION_COL__,__DORIS_DELETE_SIGN__ from ${tableName2} order by id,__DORIS_VERSION_COL__;""" + sql "set skip_delete_bitmap=true;" + sql "set skip_delete_sign=true;" + qt_sql """ select *,__DORIS_VERSION_COL__,__DORIS_DELETE_SIGN__ from ${tableName2} order by id,__DORIS_VERSION_COL__;""" + sql "set skip_delete_bitmap=false;" + sql "set skip_delete_sign=false;" } } }