dataroaring commented on code in PR #41701: URL: https://github.com/apache/doris/pull/41701#discussion_r1802411209
########## be/src/olap/memtable.cpp: ########## @@ -578,6 +546,200 @@ void MemTable::_aggregate() { } } +template <bool is_final> +void MemTable::_aggregate_for_flexible_partial_update_without_seq_col( + const vectorized::ColumnsWithTypeAndName& block_data, + vectorized::MutableBlock& mutable_block, std::vector<RowInBlock*>& temp_row_in_blocks) { + RowInBlock* prev_row = nullptr; + int row_pos = -1; + auto& skip_bitmaps = assert_cast<vectorized::ColumnBitmap*>( + mutable_block.mutable_columns()[_skip_bitmap_col_idx].get()) + ->get_data(); + auto& delete_signs = assert_cast<vectorized::ColumnInt8*>( + mutable_block.mutable_columns()[_delete_sign_col_idx].get()) + ->get_data(); + RowInBlock* row_with_delete_sign {nullptr}; + RowInBlock* row_without_delete_sign {nullptr}; + + auto finalize_rows = [&]() { + if (row_with_delete_sign != nullptr) { + temp_row_in_blocks.push_back(row_with_delete_sign); + _finalize_one_row<is_final, false>(row_with_delete_sign, block_data, ++row_pos); + row_with_delete_sign = nullptr; + } + if (row_without_delete_sign != nullptr) { + temp_row_in_blocks.push_back(row_without_delete_sign); + _finalize_one_row<is_final, false>(row_without_delete_sign, block_data, ++row_pos); + row_without_delete_sign = nullptr; + } + _arena->clear(); + }; + + auto add_row = [&](RowInBlock* row, bool with_delete_sign) { + if (with_delete_sign) { + row_with_delete_sign = row; + } else { + row_without_delete_sign = row; + } + }; + for (RowInBlock* cur_row : _row_in_blocks) { + const BitmapValue& skip_bitmap = skip_bitmaps[cur_row->_row_pos]; + bool cur_row_has_delete_sign = (!skip_bitmap.contains(_delete_sign_col_unique_id) && + delete_signs[cur_row->_row_pos] != 0); + prev_row = + (row_with_delete_sign == nullptr) ? row_without_delete_sign : row_with_delete_sign; + // compare keys, the keys of row_with_delete_sign and row_without_delete_sign is the same, + // choose any of them if it's valid + if (prev_row != nullptr && (*_vec_row_comparator)(prev_row, cur_row) == 0) { + if (cur_row_has_delete_sign) { + if (row_without_delete_sign != nullptr) { + // if there exits row without delete sign, remove it first + _clear_row_agg(row_without_delete_sign); + _stat.merged_rows++; + row_without_delete_sign = nullptr; + } + // and then unconditionally replace the previous row + prev_row = row_with_delete_sign; + } else { + prev_row = row_without_delete_sign; + } Review Comment: logic here is some complicated replated to prev_row. -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org