github-actions[bot] commented on code in PR #17542: URL: https://github.com/apache/doris/pull/17542#discussion_r1135500839
########## be/src/olap/tablet.cpp: ########## @@ -2458,13 +2530,108 @@ Status Tablet::calc_delete_bitmap(RowsetId rowset_id, pre_segments.emplace_back(seg); } } + // do partial update related works + // 1. read columns by read plan + // 2. generate new block + // 3. write a new segment and modify rowset meta + // 4. mark current keys deleted + if (is_partial_update) { + CHECK(output_block); + auto schema = rowset->tablet_schema(); + *output_block = schema->create_block(); + auto full_mutable_columns = output_block->mutate_columns(); + auto old_block = schema->create_missing_columns_block(); + auto update_block = schema->create_update_columns_block(); + + std::map<uint32_t, uint32_t> read_index_old; + read_columns_by_plan(old_block, read_plan_ori, rsid_to_rowset, &read_index_old); + + std::map<uint32_t, uint32_t> read_index_update; + read_columns_by_plan(update_block, read_plan_update, rsid_to_rowset, &read_index_update); + + // build full block + CHECK(read_index_old.size() == read_index_update.size()); + auto missing_cids = schema->get_missing_cids(); + for (auto i = 0; i < missing_cids.size(); ++i) { + for (auto idx = 0; idx < read_index_old.size(); ++idx) { + full_mutable_columns[missing_cids[i]]->insert_from( + *old_block.get_columns_with_type_and_name()[i].column.get(), + read_index_old[idx]); + } + } + auto update_cids = schema->get_update_cids(); + for (auto i = 0; i < update_cids.size(); ++i) { + for (auto idx = 0; idx < read_index_update.size(); ++idx) { + full_mutable_columns[update_cids[i]]->insert_from( + *update_block.get_columns_with_type_and_name()[i].column.get(), + read_index_update[idx]); + } + } + VLOG_DEBUG << "full block when publish: " << output_block->dump_data(); + } + LOG(INFO) << "construct delete bitmap tablet: " << tablet_id() << " rowset: " << rowset_id << " dummy_version: " << dummy_version << "bitmap num: " << delete_bitmap->delete_bitmap.size() << " cost: " << watch.get_elapse_time_us() << "(us)"; return Status::OK(); } +// read columns by read plan +// read_index: ori_pos-> block_idx +Status Tablet::read_columns_by_plan( + vectorized::Block& block, + const std::map<RowsetId, std::map<uint32_t, std::vector<RidAndPos>>>& read_plan, + const std::map<RowsetId, RowsetSharedPtr>& rsid_to_rowset, + std::map<uint32_t, uint32_t>* read_index) { + auto mutable_columns = block.mutate_columns(); + size_t read_idx = 0; + for (auto rs_it : read_plan) { + for (auto seg_it : rs_it.second) { + auto rowset_iter = rsid_to_rowset.find(rs_it.first); + CHECK(rowset_iter != rsid_to_rowset.end()); + std::vector<uint32_t> rids; + for (auto id_and_pos : seg_it.second) { + rids.emplace_back(id_and_pos.rid); + (*read_index)[id_and_pos.pos] = read_idx++; + } + for (size_t cid = 0; cid < mutable_columns.size(); ++cid) { + auto st = fetch_value_by_rowids(rowset_iter->second, seg_it.first, rids, + block.get_names()[cid], mutable_columns[cid]); + // set read value to output block + if (!st.ok()) { + LOG(INFO) << "failed to fetch value"; + return st; + } + } + } + } + return Status::OK(); +} + +void Tablet::prepare_to_read( + const RowLocation& row_location, size_t pos, + std::map<RowsetId, std::map<uint32_t, std::vector<RidAndPos>>>* read_plan) { + auto rs_it = read_plan->find(row_location.rowset_id); + if (rs_it == read_plan->end()) { + std::map<uint32_t, std::vector<RidAndPos>> segid_to_rid; + std::vector<RidAndPos> rid_pos; + rid_pos.emplace_back(RidAndPos {row_location.row_id, pos}); + segid_to_rid.emplace(row_location.segment_id, rid_pos); + read_plan->emplace(row_location.rowset_id, segid_to_rid); + return; + } + auto seg_it = rs_it->second.find(row_location.segment_id); + if (seg_it == rs_it->second.end()) { + std::vector<RidAndPos> rid_pos; + rid_pos.emplace_back(RidAndPos {row_location.row_id, pos}); + rs_it->second.emplace(row_location.segment_id, rid_pos); + return; + } + seg_it->second.emplace_back(RidAndPos {row_location.row_id, pos}); + return; +} + Status Tablet::_check_pk_in_pre_segments( Review Comment: warning: redundant return statement at the end of a function with a void return type [readability-redundant-control-flow] ```suggestion n.row_id, pos}); ``` -- 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