wgtmac commented on code in PR #652: URL: https://github.com/apache/iceberg-cpp/pull/652#discussion_r3231851004
########## src/iceberg/manifest/manifest_merge_manager.cc: ########## @@ -0,0 +1,160 @@ +/* + * 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. + */ + +#include "iceberg/manifest/manifest_merge_manager.h" + +#include <algorithm> +#include <map> +#include <utility> +#include <vector> + +#include "iceberg/manifest/manifest_entry.h" +#include "iceberg/manifest/manifest_reader.h" +#include "iceberg/table_metadata.h" +#include "iceberg/util/macros.h" + +namespace iceberg { + +ManifestMergeManager::ManifestMergeManager(int64_t target_size_bytes, + int32_t min_count_to_merge, bool merge_enabled) + : target_size_bytes_(target_size_bytes), + min_count_to_merge_(min_count_to_merge), + merge_enabled_(merge_enabled) {} + +Result<std::vector<ManifestFile>> ManifestMergeManager::MergeManifests( + const std::vector<ManifestFile>& existing_manifests, + const std::vector<ManifestFile>& new_manifests, int64_t snapshot_id, + const TableMetadata& metadata, std::shared_ptr<FileIO> file_io, + const ManifestWriterFactory& writer_factory) { + // Combine new then existing (new-first ordering is preserved in output) + std::vector<ManifestFile> all; + all.reserve(new_manifests.size() + existing_manifests.size()); + all.insert(all.end(), new_manifests.begin(), new_manifests.end()); + all.insert(all.end(), existing_manifests.begin(), existing_manifests.end()); + + if (!merge_enabled_ || std::cmp_less(all.size(), min_count_to_merge_)) { + return all; + } + + // The first (newest) manifest governs the per-bin minCountToMerge check. + const ManifestFile& first = all[0]; Review Comment: [P1] Please keep the Java empty-input behavior here before indexing into `all`. Java `ManifestMergeManager.mergeManifests` returns the input immediately when the iterator is empty, and `commit.manifest.min-count-to-merge=0` is a valid/aggressively-used setting in Java tests. With this implementation, an empty data/delete manifest input plus `min_count_to_merge_ <= 0` gets past the size check and reads `all[0]`, which is UB/crash instead of returning an empty manifest list. -- 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]
