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 192ab750b11 [cherry-pick](branch-2.0) Pick "[fix](partial update) Support partial update when the date default value is 'current_date'. This PR is a extension of PR #32926. (#33394)" (#37605) 192ab750b11 is described below commit 192ab750b11520f1fec87dc39b578b1063dbd6b8 Author: abmdocrt <yukang.lian2...@gmail.com> AuthorDate: Mon Jul 15 14:14:09 2024 +0800 [cherry-pick](branch-2.0) Pick "[fix](partial update) Support partial update when the date default value is 'current_date'. This PR is a extension of PR #32926. (#33394)" (#37605) pick #33394 and #33177 --- be/src/olap/rowset/segment_v2/segment_writer.cpp | 25 ++++++++++++-- .../partial_update/test_partial_update.out | 18 ++++++++++ .../partial_update/test_partial_update.groovy | 38 +++++++++++++++++++++- 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/be/src/olap/rowset/segment_v2/segment_writer.cpp b/be/src/olap/rowset/segment_v2/segment_writer.cpp index 31f22c48be4..64e91be3e9a 100644 --- a/be/src/olap/rowset/segment_v2/segment_writer.cpp +++ b/be/src/olap/rowset/segment_v2/segment_writer.cpp @@ -635,8 +635,29 @@ Status SegmentWriter::fill_missing_columns(vectorized::MutableColumns& mutable_f for (auto i = 0; i < cids_missing.size(); ++i) { const auto& column = _tablet_schema->column(cids_missing[i]); if (column.has_default_value()) { - const auto& default_value = - _opts.rowset_ctx->partial_update_info->default_values[i]; + std::string default_value; + if (UNLIKELY(_tablet_schema->column(cids_missing[i]).type() == + FieldType::OLAP_FIELD_TYPE_DATETIMEV2 && + to_lower(_tablet_schema->column(cids_missing[i]).default_value()) + .find(to_lower("CURRENT_TIMESTAMP")) != + std::string::npos)) { + vectorized::DateV2Value<vectorized::DateTimeV2ValueType> dtv; + dtv.from_unixtime(_opts.rowset_ctx->partial_update_info->timestamp_ms / 1000, + _opts.rowset_ctx->partial_update_info->timezone); + default_value = dtv.debug_string(); + } else if (UNLIKELY( + _tablet_schema->column(cids_missing[i]).type() == + FieldType::OLAP_FIELD_TYPE_DATEV2 && + to_lower(_tablet_schema->column(cids_missing[i]).default_value()) + .find(to_lower("CURRENT_DATE")) != + std::string::npos)) { + vectorized::DateV2Value<vectorized::DateV2ValueType> dv; + dv.from_unixtime(_opts.rowset_ctx->partial_update_info->timestamp_ms / 1000, + _opts.rowset_ctx->partial_update_info->timezone); + default_value = dv.debug_string(); + } else { + default_value = _tablet_schema->column(cids_missing[i]).default_value(); + } vectorized::ReadBuffer rb(const_cast<char*>(default_value.c_str()), default_value.size()); old_value_block.get_by_position(i).type->from_string( diff --git a/regression-test/data/unique_with_mow_p0/partial_update/test_partial_update.out b/regression-test/data/unique_with_mow_p0/partial_update/test_partial_update.out index 19b048316ae..19429870ef0 100644 --- a/regression-test/data/unique_with_mow_p0/partial_update/test_partial_update.out +++ b/regression-test/data/unique_with_mow_p0/partial_update/test_partial_update.out @@ -38,6 +38,15 @@ -- !select_timestamp -- 1 +-- !select_timestamp2 -- +0 + +-- !select_date -- +1 + +-- !select_date2 -- +2 + -- !select_default -- 1 doris 200 123 1 2 doris2 400 223 1 @@ -77,3 +86,12 @@ -- !select_timestamp -- 1 +-- !select_timestamp2 -- +0 + +-- !select_date -- +1 + +-- !select_date2 -- +2 + diff --git a/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update.groovy b/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update.groovy index c574f9f3422..bb9bdff0817 100644 --- a/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update.groovy +++ b/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update.groovy @@ -185,7 +185,7 @@ suite("test_primary_key_partial_update", "p0") { select * from ${tableName} order by id; """ - // drop drop + // drop table sql """ DROP TABLE IF EXISTS ${tableName} """ sql """ CREATE TABLE ${tableName} ( @@ -206,6 +206,42 @@ suite("test_primary_key_partial_update", "p0") { sql "INSERT INTO ${tableName}(`name`, `userid`, `corp_name`) VALUES ('test1', 1234567, 'A');" qt_select_timestamp "select count(*) from ${tableName} where `ctime` > \"1970-01-01\"" + + sql "set time_zone = 'America/New_York'" + + Thread.sleep(5000) + + sql "INSERT INTO ${tableName}(`name`, `userid`, `corp_name`) VALUES ('test2', 1234567, 'A');" + + qt_select_timestamp2 "SELECT ABS(TIMESTAMPDIFF(HOUR, MIN(ctime), MAX(ctime))) AS time_difference_hours FROM ${tableName};" + + // drop table + sql """ DROP TABLE IF EXISTS ${tableName} """ + + sql """ SET enable_nereids_planner=true; """ + sql """ CREATE TABLE ${tableName} ( + `name` VARCHAR(600) NULL, + `userid` INT NOT NULL, + `seq` BIGINT NULL, + `ctime` DATETIME(3) DEFAULT CURRENT_TIMESTAMP(3), + `corp_name` VARCHAR(600) NOT NULL + ) ENGINE = OLAP UNIQUE KEY(`name`, `userid`) COMMENT 'OLAP' DISTRIBUTED BY HASH(`name`) BUCKETS 10 + PROPERTIES ("replication_num" = "1", + "enable_unique_key_merge_on_write" = "true", + "store_row_column" = "${use_row_store}"); """ + + sql "set enable_unique_key_partial_update=true;" + sql "set enable_insert_strict=false;" + + sql "INSERT INTO ${tableName}(`name`, `userid`, `corp_name`) VALUES ('test1', 1234567, 'A');" + + qt_select_date "select count(*) from ${tableName} where `ctime` > \"1970-01-01\"" + + sql "set time_zone = 'America/New_York'" + + sql "INSERT INTO ${tableName}(`name`, `userid`, `corp_name`) VALUES ('test2', 1234567, 'B');" + + qt_select_date2 "select count(*) from ${tableName} where `ctime` > \"1970-01-01\"" } } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org