zhannngchen commented on code in PR #32200:
URL: https://github.com/apache/doris/pull/32200#discussion_r1546052129


##########
regression-test/suites/unique_with_mow_p0/partial_update/test_agg_partial_update_insert_into.groovy:
##########
@@ -0,0 +1,87 @@
+// 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
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_agg_partial_update_insert_into", "p0") {
+
+    String db = context.config.getDbNameByFile(context.file)
+    sql "select 1;" // to create database
+
+    connect(user = context.config.jdbcUser, password = 
context.config.jdbcPassword, url = context.config.jdbcUrl) {

Review Comment:
   有没有测试segmentwriter?



##########
be/src/olap/tablet_schema.cpp:
##########
@@ -1470,4 +1470,54 @@ std::string 
TabletSchema::deterministic_string_serialize(const TabletSchemaPB& s
     return output;
 }
 
+Status TabletSchema::make_full_block(std::shared_ptr<vectorized::Block>& 
full_block_ptr,
+                                     const vectorized::Block* block, size_t 
num_rows,
+                                     std::vector<uint32_t>& update_cids,
+                                     std::vector<uint32_t>& missing_cids) {
+    full_block_ptr = std::make_shared<vectorized::Block>(this->create_block());
+    size_t input_id = 0;
+    for (auto i : update_cids) {
+        full_block_ptr->replace_by_position(i, 
block->get_by_position(input_id++).column);
+    }
+    auto mutable_full_columns = full_block_ptr->mutate_columns();
+    auto old_value_block = create_block_by_cids(missing_cids);
+    CHECK(missing_cids.size() == old_value_block.columns());
+
+    // build default value columns
+    auto default_value_block = old_value_block.clone_empty();
+    auto mutable_default_value_columns = default_value_block.mutate_columns();
+
+    for (auto i = 0; i < missing_cids.size(); ++i) {
+        const auto& missing_column = this->column(missing_cids[i]);
+        if (missing_column.has_default_value()) {
+            auto default_value = this->column(missing_cids[i]).default_value();
+            vectorized::ReadBuffer rb(const_cast<char*>(default_value.c_str()),
+                                      default_value.size());
+            
RETURN_IF_ERROR(old_value_block.get_by_position(i).type->from_string(
+                    rb, mutable_default_value_columns[i].get()));
+        }
+    }
+
+    for (auto idx = 0; idx < num_rows; idx++) {
+        for (auto i = 0; i < missing_cids.size(); ++i) {
+            // if the column has default value, fill it with default value

Review Comment:
   The comment is outdated



##########
be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp:
##########
@@ -694,13 +694,29 @@ Status VerticalSegmentWriter::batch_block(const 
vectorized::Block* block, size_t
         _opts.rowset_ctx->partial_update_info->is_partial_update &&
         _opts.write_type == DataWriteType::TYPE_DIRECT &&
         !_opts.rowset_ctx->is_transient_rowset_writer) {
-        if (block->columns() <= _tablet_schema->num_key_columns() ||
-            block->columns() >= _tablet_schema->num_columns()) {
-            return Status::InternalError(fmt::format(
-                    "illegal partial update block columns: {}, num key 
columns: {}, total "
-                    "schema columns: {}",
-                    block->columns(), _tablet_schema->num_key_columns(),
-                    _tablet_schema->num_columns()));
+        if (_tablet_schema->keys_type() != UNIQUE_KEYS && 
_tablet_schema->keys_type() != AGG_KEYS) {
+            return Status::InternalError(fmt::format("illegal partial update 
key type: {}",
+                                                     
_tablet_schema->keys_type()));
+        }
+        if (_tablet_schema->keys_type() == UNIQUE_KEYS &&
+            (block->columns() <= _tablet_schema->num_key_columns() ||
+             block->columns() >= _tablet_schema->num_columns())) {
+            return Status::InternalError(
+                    fmt::format("illegal partial update key type {}, block 
columns: {}, num key "
+                                "columns: {}, total "
+                                "schema columns: {}",
+                                _tablet_schema->keys_type(), block->columns(),
+                                _tablet_schema->num_key_columns(), 
_tablet_schema->num_columns()));
+        }
+        if (_tablet_schema->keys_type() == AGG_KEYS &&
+            (block->columns() <= _tablet_schema->num_key_columns() ||
+             block->columns() > _tablet_schema->num_columns())) {

Review Comment:
   Why it's not same with L703?



##########
be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp:
##########
@@ -728,24 +745,48 @@ Status VerticalSegmentWriter::write_batch() {
         }
         return Status::OK();
     }
+    bool is_agg_partial_update = _opts.rowset_ctx->partial_update_info &&
+                                 
_opts.rowset_ctx->partial_update_info->is_partial_update &&
+                                 _tablet_schema->keys_type() == AGG_KEYS &&
+                                 _opts.write_type == 
DataWriteType::TYPE_DIRECT;
+    std::vector<std::shared_ptr<vectorized::Block>> full_blocks;
+    if (is_agg_partial_update) {
+        for (auto& data : _batched_blocks) {
+            std::shared_ptr<vectorized::Block> full_block_ptr = nullptr;
+            RETURN_IF_ERROR(_tablet_schema->make_full_block(
+                    full_block_ptr, data.block, data.num_rows,
+                    _opts.rowset_ctx->partial_update_info->update_cids,
+                    _opts.rowset_ctx->partial_update_info->missing_cids));
+            full_blocks.emplace_back(full_block_ptr);

Review Comment:
   is it possiable to replace blocks in `_batched_blocks` with full block?



##########
be/src/olap/memtable.cpp:
##########
@@ -107,6 +107,10 @@ void MemTable::_init_agg_functions(const 
vectorized::Block* block) {
             function = 
vectorized::AggregateFunctionSimpleFactory::instance().get(
                     "replace_load", {block->get_data_type(cid)},
                     block->get_data_type(cid)->is_nullable());
+        } else if (_keys_type == KeysType::AGG_KEYS && _is_partial_update) {
+            function = 
vectorized::AggregateFunctionSimpleFactory::instance().get(

Review Comment:
   Add comment to explain this



##########
be/src/olap/tablet_schema.h:
##########
@@ -435,6 +435,9 @@ class TabletSchema {
 
     void update_tablet_columns(const TabletSchema& tablet_schema,
                                const std::vector<TColumn>& t_columns);
+    Status make_full_block(std::shared_ptr<vectorized::Block>& full_block_ptr,

Review Comment:
   Add comment for this method



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to