HappenLee commented on code in PR #31827: URL: https://github.com/apache/doris/pull/31827#discussion_r1535004008
########## be/src/exec/tablet_info.cpp: ########## @@ -551,16 +504,84 @@ Status VOlapTablePartitionParam::_create_partition_key(const TExprNode& t_expr, part_key->second = column->size() - 1; return Status::OK(); } +// NOLINTEND(readability-function-size) + +Status VOlapTablePartitionParam::_create_partition_keys(const std::vector<TExprNode>& t_exprs, + BlockRow* part_key) { + for (int i = 0; i < t_exprs.size(); i++) { + RETURN_IF_ERROR(_create_partition_key(t_exprs[i], part_key, _partition_slot_locs[i])); + } + return Status::OK(); +} + +Status VOlapTablePartitionParam::generate_partition_from(const TOlapTablePartition& t_part, + VOlapTablePartition*& part_result) { + DCHECK(part_result == nullptr); + // here we set the default value of partition bounds first! if it doesn't have some key, it will be -1. + part_result = _obj_pool.add(new VOlapTablePartition(&_partition_block)); + part_result->id = t_part.id; + part_result->is_mutable = t_part.is_mutable; + // only load_to_single_tablet = true will set load_tablet_idx + if (t_part.__isset.load_tablet_idx) { + part_result->load_tablet_idx = t_part.load_tablet_idx; + } + + if (_is_in_partition) { + for (const auto& keys : t_part.in_keys) { + RETURN_IF_ERROR(_create_partition_keys( + keys, &part_result->in_keys.emplace_back(&_partition_block, -1))); + } + if (t_part.__isset.is_default_partition && t_part.is_default_partition && + _default_partition == nullptr) { + _default_partition = part_result; + } + } else { // range + if (t_part.__isset.start_keys) { + RETURN_IF_ERROR(_create_partition_keys(t_part.start_keys, &part_result->start_key)); + } + // we generate the right bound but not insert into partition map + if (t_part.__isset.end_keys) { + RETURN_IF_ERROR(_create_partition_keys(t_part.end_keys, &part_result->end_key)); + } + } + + part_result->num_buckets = t_part.num_buckets; + auto num_indexes = _schema->indexes().size(); + if (t_part.indexes.size() != num_indexes) { + return Status::InternalError( + "number of partition's index is not equal with schema's" + ", num_part_indexes={}, num_schema_indexes={}", + t_part.indexes.size(), num_indexes); + } + part_result->indexes = t_part.indexes; + std::sort(part_result->indexes.begin(), part_result->indexes.end(), + [](const OlapTableIndexTablets& lhs, const OlapTableIndexTablets& rhs) { + return lhs.index_id < rhs.index_id; + }); + // check index + for (int j = 0; j < num_indexes; ++j) { + if (part_result->indexes[j].index_id != _schema->indexes()[j]->index_id) { + std::stringstream ss; Review Comment: do not use `std::stringstream ` -- 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