29#include <unordered_map>
49 int64_t apply_sequence_number;
52 mutable std::unordered_map<int32_t, Literal> lower_bounds;
53 mutable std::unordered_map<int32_t, Literal> upper_bounds;
54 mutable bool bounds_converted =
false;
58 wrapped(std::move(entry)),
63 return !wrapped.
data_file->lower_bounds.empty() &&
70 ICEBERG_RETURN_UNEXPECTED(ConvertBoundsIfNeeded());
71 auto it = lower_bounds.find(
id);
72 return it != lower_bounds.cend() ? std::make_optional(std::cref(it->second))
79 ICEBERG_RETURN_UNEXPECTED(ConvertBoundsIfNeeded());
80 auto it = upper_bounds.find(
id);
81 return it != upper_bounds.cend() ? std::make_optional(std::cref(it->second))
87 Status ConvertBoundsIfNeeded()
const;
93 if (data_lower > delete_upper) {
96 if (delete_lower > data_upper) {
103inline bool AllNull(
const std::map<int32_t, int64_t>& null_counts,
104 const std::map<int32_t, int64_t>& value_counts, int32_t field_id,
110 auto null_it = null_counts.find(field_id);
111 auto value_it = value_counts.find(field_id);
112 if (null_it == null_counts.cend() || value_it == value_counts.cend()) {
116 return null_it->second == value_it->second;
120inline bool AllNonNull(
const std::map<int32_t, int64_t>& null_counts, int32_t field_id,
126 auto it = null_counts.find(field_id);
127 if (it == null_counts.cend()) {
131 return it->second <= 0;
135inline bool ContainsNull(
const std::map<int32_t, int64_t>& null_counts, int32_t field_id,
141 auto it = null_counts.find(field_id);
142 if (it == null_counts.cend()) {
146 return it->second > 0;
166 std::vector<std::shared_ptr<DataFile>>
Filter(int64_t seq);
172 bool empty()
const {
return files_.empty(); }
175 void IndexIfNeeded();
177 std::vector<ManifestEntry> files_;
178 std::vector<int64_t> seqs_;
179 bool indexed_ =
false;
205 bool empty()
const {
return files_.empty(); }
208 void IndexIfNeeded();
211 std::vector<EqualityDeleteFile> files_;
212 std::vector<int64_t> seqs_;
213 bool indexed_ =
false;
277 std::shared_ptr<FileIO> io, std::shared_ptr<Schema> schema,
278 std::unordered_map<int32_t, std::shared_ptr<PartitionSpec>> specs_by_id,
279 std::vector<ManifestFile> delete_manifests);
282 friend class Builder;
286 std::unique_ptr<internal::EqualityDeletes> global_deletes,
287 std::unique_ptr<
PartitionMap<std::unique_ptr<internal::EqualityDeletes>>>
288 eq_deletes_by_partition,
289 std::unique_ptr<
PartitionMap<std::unique_ptr<internal::PositionDeletes>>>
290 pos_deletes_by_partition,
292 std::unordered_map<std::string, std::unique_ptr<internal::PositionDeletes>>>
294 std::unique_ptr<std::unordered_map<std::string, ManifestEntry>> dv_by_path);
298 int64_t seq,
const DataFile& data_file)
const;
300 int64_t seq,
const DataFile& data_file)
const;
302 int64_t seq,
const DataFile& data_file)
const;
304 int64_t seq,
const DataFile& data_file)
const;
308 std::unique_ptr<internal::EqualityDeletes> global_deletes_;
309 std::unique_ptr<PartitionMap<std::unique_ptr<internal::EqualityDeletes>>>
310 eq_deletes_by_partition_;
311 std::unique_ptr<PartitionMap<std::unique_ptr<internal::PositionDeletes>>>
312 pos_deletes_by_partition_;
314 std::unordered_map<std::string, std::unique_ptr<internal::PositionDeletes>>>
315 pos_deletes_by_path_;
316 std::unique_ptr<std::unordered_map<std::string, ManifestEntry>> dv_by_path_;
318 bool has_eq_deletes_ =
false;
319 bool has_pos_deletes_ =
false;
320 bool is_empty_ =
true;
326 Builder(std::shared_ptr<FileIO> io, std::shared_ptr<Schema> schema,
327 std::unordered_map<int32_t, std::shared_ptr<PartitionSpec>> specs_by_id,
328 std::vector<ManifestFile> delete_manifests);
332 Builder(Builder&&) noexcept;
333 Builder& operator=(Builder&&) noexcept;
334 Builder(const Builder&) = delete;
335 Builder& operator=(const Builder&) = delete;
340 Builder& AfterSequenceNumber(int64_t seq);
355 Builder& CaseSensitive(
bool case_sensitive);
358 Builder& IgnoreResiduals();
364 Builder& PlanWith(OptionalExecutor executor);
381 Status AddPositionDelete(
382 std::unordered_map<
std::
string,
std::unique_ptr<internal::PositionDeletes>>&
384 PartitionMap<
std::unique_ptr<internal::PositionDeletes>>& deletes_by_partition,
388 Status AddEqualityDelete(
389 internal::EqualityDeletes& global_deletes,
390 PartitionMap<
std::unique_ptr<internal::EqualityDeletes>>& deletes_by_partition,
397 int64_t min_sequence_number_ = 0;
401 OptionalExecutor executor_;
402 bool case_sensitive_ = true;
403 bool ignore_residuals_ = false;
An index of delete files by sequence number.
Definition delete_file_index.h:229
Builder(std::shared_ptr< FileIO > io, std::shared_ptr< Schema > schema, std::unordered_map< int32_t, std::shared_ptr< PartitionSpec > > specs_by_id, std::vector< ManifestFile > delete_manifests)
Construct a builder from manifest files.
Result< std::vector< std::shared_ptr< DataFile > > > ForDataFile(int64_t sequence_number, const DataFile &file) const
Get the delete files that apply to a data file with a specific sequence number.
bool empty() const
Check if this index is empty (has no delete files).
std::vector< std::shared_ptr< DataFile > > ReferencedDeleteFiles() const
Get all delete files referenced by this index. TODO(gangwu): use lazy iterator to avoid large memory ...
static Result< Builder > BuilderFor(std::shared_ptr< FileIO > io, std::shared_ptr< Schema > schema, std::unordered_map< int32_t, std::shared_ptr< PartitionSpec > > specs_by_id, std::vector< ManifestFile > delete_manifests)
Create a builder for constructing a DeleteFileIndex from manifest files.
Result< std::vector< std::shared_ptr< DataFile > > > ForEntry(const ManifestEntry &entry) const
Get the delete files that apply to a manifest entry.
bool has_position_deletes() const
Check if this index has any position delete files.
bool has_equality_deletes() const
Check if this index has any equality delete files.
Base class for collecting errors in the builder pattern.
Definition error_collector.h:93
Represents a boolean expression tree.
Definition expression.h:37
Pluggable module for reading, writing, and deleting files.
Definition file_io.h:128
Literal is a literal value that is associated with a primitive type.
Definition literal.h:42
A map that uses a pair of spec ID and partition tuple as keys.
Definition partition_value_util.h:115
A set that uses a pair of spec ID and partition tuple as elements.
Definition partition_value_util.h:204
A partition spec for a Table.
Definition partition_spec.h:47
Live scan metrics collected during a table scan operation.
Definition scan_report.h:94
A schema for a Table.
Definition schema.h:51
A group of equality delete files sorted by apply sequence number.
Definition delete_file_index.h:186
Status Add(ManifestEntry &&entry)
Add an equality delete file to this group.
Result< std::vector< std::shared_ptr< DataFile > > > Filter(int64_t seq, const DataFile &data_file)
Filter equality deletes that apply to the given data file.
std::vector< std::shared_ptr< DataFile > > ReferencedDeleteFiles()
Get all delete files in this group.
bool empty() const
Check if this group is empty.
Definition delete_file_index.h:205
A group of position delete files sorted by the sequence number they apply to.
Definition delete_file_index.h:157
bool empty() const
Check if this group is empty.
Definition delete_file_index.h:172
std::vector< std::shared_ptr< DataFile > > ReferencedDeleteFiles()
Get all delete files in this group.
std::vector< std::shared_ptr< DataFile > > Filter(int64_t seq)
Returns all delete files with data_sequence_number >= the given sequence number.
Status Add(ManifestEntry &&entry)
Add a position delete file to this group.
bool AllNull(const std::map< int32_t, int64_t > &null_counts, const std::map< int32_t, int64_t > &value_counts, int32_t field_id, bool is_required)
Check if a value count map indicates all values are null.
Definition delete_file_index.h:103
bool RangesOverlap(const Literal &data_lower, const Literal &data_upper, const Literal &delete_lower, const Literal &delete_upper)
Check if two ranges overlap.
Definition delete_file_index.h:91
ICEBERG_EXPORT Result< bool > CanContainEqDeletesForFile(const DataFile &data_file, const EqualityDeleteFile &delete_file)
Check if an equality delete file can contain deletes for a data file.
bool ContainsNull(const std::map< int32_t, int64_t > &null_counts, int32_t field_id, bool is_required)
Check if the column contains any null values.
Definition delete_file_index.h:135
bool AllNonNull(const std::map< int32_t, int64_t > &null_counts, int32_t field_id, bool is_required)
Check if all values are non-null.
Definition delete_file_index.h:120
Define task executor interfaces.
Define symbol visibility macros for core Iceberg APIs.
Define typed literal values used by expressions.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
std::expected< T, E > Result
Result alias.
Definition result.h:88
Define Result, Status, and error helpers.
DataFile carries data file path, partition tuple, metrics, ...
Definition manifest_entry.h:62
A manifest is an immutable Avro file that lists data files or delete files, along with each file's pa...
Definition manifest_entry.h:318
std::optional< int64_t > sequence_number
Definition manifest_entry.h:339
std::shared_ptr< DataFile > data_file
Definition manifest_entry.h:355
Entry in a manifest list.
Definition manifest_list.h:85
Wrapper for equality delete files that caches converted bounds.
Definition delete_file_index.h:46
Result< std::optional< std::reference_wrapper< const Literal > > > UpperBound(int32_t id) const
Get the upper bound for a field ID.
Definition delete_file_index.h:77
Result< std::optional< std::reference_wrapper< const Literal > > > LowerBound(int32_t id) const
Get the lower bound for a field ID.
Definition delete_file_index.h:68
bool HasLowerAndUpperBounds() const
Check if this delete file has both lower and upper bounds.
Definition delete_file_index.h:62