iceberg-cpp
Loading...
Searching...
No Matches
manifest_filter_manager.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
25
26#include <cstdint>
27#include <functional>
28#include <memory>
29#include <string>
30#include <unordered_map>
31#include <unordered_set>
32#include <vector>
33
34#include "iceberg/iceberg_export.h"
37#include "iceberg/result.h"
38#include "iceberg/snapshot.h"
39#include "iceberg/type_fwd.h"
41#include "iceberg/util/partition_value_util.h"
42
43namespace iceberg {
44
56class ICEBERG_EXPORT ManifestFilterManager {
57 public:
58 using PartitionSpecsById = std::unordered_map<int32_t, std::shared_ptr<PartitionSpec>>;
59
60 static Result<std::unique_ptr<ManifestFilterManager>> Make(
61 ManifestContent content, std::shared_ptr<FileIO> file_io,
62 std::function<Status(const std::string&)> delete_file = {});
64
66 ManifestFilterManager& operator=(const ManifestFilterManager&) = delete;
67
74 Status DeleteByRowFilter(std::shared_ptr<Expression> expr);
75
77 void CaseSensitive(bool case_sensitive);
78
84 Status DeleteFile(std::string_view path);
85
92 Status DeleteFile(std::shared_ptr<DataFile> file);
93
98 const DataFileSet& FilesToBeDeleted() const;
99
102 const std::vector<std::shared_ptr<DataFile>>& DeletedFiles() const;
103
106 int32_t DuplicateDeletesCount() const { return duplicate_deletes_count_; }
107
110 Result<SnapshotSummaryBuilder> BuildSummary(
111 const std::vector<ManifestFile>& manifests,
112 const PartitionSpecsById& specs_by_id) const;
113
120 Status DropPartition(int32_t spec_id, PartitionValues partition);
121
124 void FailMissingDeletePaths();
125
128 void FailAnyDelete();
129
133 int32_t ReplacedManifestsCount() const { return replaced_manifests_count_; }
134
136 bool ContainsDeletes() const;
137
148 Status DropDeleteFilesOlderThan(int64_t sequence_number);
149
158 void RemoveDanglingDeletesFor(const DataFileSet& deleted_files);
159
169 Result<std::vector<ManifestFile>> FilterManifests(
170 const TableMetadata& metadata, const std::shared_ptr<Snapshot>& base_snapshot,
171 const ManifestWriterFactory& writer_factory);
172
177 Result<std::vector<ManifestFile>> FilterManifests(
178 const std::shared_ptr<Schema>& schema, const TableMetadata& metadata,
179 const std::shared_ptr<Snapshot>& base_snapshot,
180 const ManifestWriterFactory& writer_factory);
181
192 Result<std::vector<ManifestFile>> FilterManifests(
193 const std::shared_ptr<Schema>& schema, const PartitionSpecsById& specs_by_id,
194 const std::vector<const ManifestFile*>& manifests,
195 const ManifestWriterFactory& writer_factory);
196
199 Status CleanUncommitted(const std::unordered_set<std::string>& committed);
200
201 private:
202 ManifestFilterManager(ManifestContent content, std::shared_ptr<FileIO> file_io,
203 std::function<Status(const std::string&)> delete_file);
204
206 Result<bool> CanContainExpressionDeletes(const ManifestFile& manifest,
207 const std::shared_ptr<Schema>& schema,
208 const PartitionSpecsById& specs_by_id);
209
215 Result<bool> CanContainDroppedPartitions(const ManifestFile& manifest) const;
216
218 Result<bool> CanContainDroppedFiles(const ManifestFile& manifest) const;
219
221 Result<bool> CanContainDeletedFiles(const ManifestFile& manifest,
222 const std::shared_ptr<Schema>& schema,
223 const PartitionSpecsById& specs_by_id,
224 bool trust_manifest_references);
225
226 bool CanTrustManifestReferences(
227 const std::vector<const ManifestFile*>& manifests) const;
228
229 struct FilteredManifestDeletes {
230 std::vector<std::shared_ptr<DataFile>> files;
231 int32_t duplicate_deletes_count = 0;
232 };
233
234 Result<ManifestFile> FilterManifest(const std::shared_ptr<Schema>& schema,
235 const PartitionSpecsById& specs_by_id,
236 const ManifestFile& manifest,
237 bool trust_manifest_references,
238 const ManifestWriterFactory& writer_factory);
239
240 Result<bool> ManifestHasDeletedFiles(const std::vector<ManifestEntry>& entries,
241 const std::shared_ptr<Schema>& schema,
242 const PartitionSpecsById& specs_by_id,
243 int32_t manifest_spec_id);
244
245 Result<ManifestFile> FilterManifestWithDeletedFiles(
246 const std::vector<ManifestEntry>& entries, int32_t manifest_spec_id,
247 const std::shared_ptr<Schema>& schema, const PartitionSpecsById& specs_by_id,
248 const ManifestWriterFactory& writer_factory);
249
250 Status ValidateRequiredDeletes() const;
251
252 Status InvalidateFilteredCache();
253 void ResetDeletedFiles();
254
256 Result<ManifestEvaluator*> GetManifestEvaluator(const std::shared_ptr<Schema>& schema,
257 const PartitionSpecsById& specs_by_id,
258 int32_t spec_id);
259
261 Result<ResidualEvaluator*> GetResidualEvaluator(const std::shared_ptr<Schema>& schema,
262 const PartitionSpecsById& specs_by_id,
263 int32_t spec_id);
264
266 Result<bool> ShouldDelete(const ManifestEntry& entry,
267 const std::shared_ptr<Schema>& schema,
268 const PartitionSpecsById& specs_by_id,
269 int32_t manifest_spec_id);
270
271 const ManifestContent manifest_content_;
272 std::shared_ptr<FileIO> file_io_;
273 std::function<Status(const std::string&)> delete_file_;
274
275 std::shared_ptr<Expression> delete_expr_;
276 std::unordered_set<std::string> delete_paths_;
277 // Delete files explicitly registered for deletion by object identity.
278 DeleteFileSet delete_files_to_delete_;
279 // Data files explicitly registered for deletion by object identity.
280 DataFileSet data_files_to_delete_;
281 // Data files to remove: explicit object deletes plus files found while filtering.
282 DataFileSet data_files_;
283 // Delete files to remove: explicit object deletes plus files found while filtering.
284 DeleteFileSet delete_files_;
285 std::unordered_map<ManifestFile, FilteredManifestDeletes>
286 filtered_manifest_to_deleted_files_;
287 // Ordered files deleted by the latest filter pass, used for summaries.
288 std::vector<std::shared_ptr<DataFile>> deleted_files_;
289 // Data-file identity set for latest-pass dedup and required-delete validation.
290 DataFileSet deleted_data_file_set_;
291 // Delete-file identity set for latest-pass dedup and required-delete validation.
292 DeleteFileSet deleted_delete_file_set_;
293 PartitionSet drop_partitions_;
294 bool fail_missing_delete_paths_{false};
295 bool fail_any_delete_{false};
296 bool case_sensitive_{true};
297 int32_t duplicate_deletes_count_{0};
298 int32_t replaced_manifests_count_{0};
299
300 // minimum data sequence number; delete entries older than this are dropped
301 int64_t min_sequence_number_{0};
302 // paths of data files that were removed; DVs referencing these are dangling
303 std::unordered_set<std::string> removed_data_file_paths_;
304
305 std::unordered_map<ManifestFile, ManifestFile> filtered_manifests_;
306
307 std::unordered_map<int32_t, std::unique_ptr<ManifestEvaluator>>
308 manifest_evaluator_cache_;
309 std::unordered_map<int32_t, std::unique_ptr<ResidualEvaluator>>
310 residual_evaluator_cache_;
311};
312
313} // namespace iceberg
A set of DataFile pointers with insertion order preserved and deduplicated by file path.
Definition data_file_set.h:44
Filters an existing snapshot's manifest list.
Definition manifest_filter_manager.h:56
int32_t ReplacedManifestsCount() const
Returns the number of manifests rewritten (replaced) by the last FilterManifests() call....
Definition manifest_filter_manager.h:133
int32_t DuplicateDeletesCount() const
Returns how many duplicate file deletes were found in the most recent FilterManifests() call.
Definition manifest_filter_manager.h:106
StructLike wrapper for a vector of literals that represent partition values.
Definition partition_values.h:36
ManifestContent
The type of files tracked by the manifest, either data or delete files; 0 for all v1 manifests.
Definition manifest_list.h:77
std::function< Result< std::unique_ptr< ManifestWriter > >(int32_t spec_id, ManifestContent content)> ManifestWriterFactory
Factory type for creating ManifestWriter instances.
Definition manifest_writer.h:169
Entry in a manifest list.
Definition manifest_list.h:85
Represents the metadata for an Iceberg table.
Definition table_metadata.h:73