3131
3232#include " iceberg/deletes/dv_util_internal.h"
3333#include " iceberg/deletes/position_delete_index.h"
34- #include " iceberg/file_format.h"
3534#include " iceberg/file_io.h" // IWYU pragma: keep
3635#include " iceberg/manifest/manifest_entry.h"
3736#include " iceberg/partition_spec.h"
@@ -55,6 +54,7 @@ class DVWriter::Impl {
5554 PositionDeleteIndex positions;
5655 std::shared_ptr<PartitionSpec> spec;
5756 PartitionValues partition;
57+ puffin::BlobMetadata blob;
5858 };
5959
6060 Deletes& DeletesFor (std::string_view referenced_data_file,
@@ -107,30 +107,31 @@ class DVWriter::Impl {
107107
108108 for (auto & [path, deletes] : deletes_by_path_) {
109109 ICEBERG_RETURN_UNEXPECTED (LoadPreviousDeletes (path, deletes));
110- }
111-
112- for (auto & [_, deletes] : deletes_by_path_) {
113110 ICEBERG_RETURN_UNEXPECTED (deletes.positions .PrepareForSerialization ());
114111 }
115112
116113 ICEBERG_ASSIGN_OR_RAISE (auto output_file, options_.io ->NewOutputFile (options_.path ));
117- const std::string output_path (options_.path );
118114 ICEBERG_ASSIGN_OR_RAISE (
119115 auto writer, puffin::PuffinWriter::Make (
120116 std::move (output_file),
121117 {{std::string (puffin::StandardPuffinProperties::kCreatedBy ),
122118 ICEBERG_FULL_VERSION_STRING }}));
123119
124120 for (auto & [path, deletes] : deletes_by_path_) {
125- ICEBERG_RETURN_UNEXPECTED (Write (*writer, path, deletes));
121+ ICEBERG_ASSIGN_OR_RAISE (deletes.blob ,
122+ DVUtil::WriteDVBlob (*writer, path, deletes.positions ));
126123 }
127124
128125 ICEBERG_RETURN_UNEXPECTED (writer->Finish ());
129126 ICEBERG_ASSIGN_OR_RAISE (const int64_t file_size, writer->FileSize ());
130127
131- for (const auto & [path, _ ] : deletes_by_path_) {
128+ for (const auto & [path, deletes ] : deletes_by_path_) {
132129 result_.referenced_data_files .push_back (path);
133- ICEBERG_ASSIGN_OR_RAISE (auto data_file, CreateDV (output_path, file_size, path));
130+ ICEBERG_ASSIGN_OR_RAISE (
131+ auto data_file,
132+ DVUtil::MakeDVDataFile (options_.path , file_size, path, deletes.partition ,
133+ deletes.positions .Cardinality (), deletes.spec ,
134+ deletes.blob ));
134135 result_.data_files .push_back (std::move (data_file));
135136 }
136137
@@ -161,42 +162,8 @@ class DVWriter::Impl {
161162 return {};
162163 }
163164
164- Status Write (puffin::PuffinWriter& writer, std::string_view path, Deletes& deletes) {
165- ICEBERG_ASSIGN_OR_RAISE (auto blob_metadata,
166- DVUtil::WriteDVBlob (writer, path, deletes.positions ));
167- blobs_by_path_.insert_or_assign (std::string (path), std::move (blob_metadata));
168- return {};
169- }
170-
171- Result<std::shared_ptr<DataFile>> CreateDV (const std::string& path, int64_t size,
172- std::string_view referenced_data_file) {
173- auto deletes = deletes_by_path_.find (referenced_data_file);
174- ICEBERG_CHECK (deletes != deletes_by_path_.end (), " Missing deletion vector for {}" ,
175- referenced_data_file);
176- auto blob_metadata = blobs_by_path_.find (referenced_data_file);
177- ICEBERG_CHECK (blob_metadata != blobs_by_path_.end (),
178- " Missing deletion vector blob for {}" , referenced_data_file);
179-
180- return std::make_shared<DataFile>(DataFile{
181- .content = DataFile::Content::kPositionDeletes ,
182- .file_path = path,
183- .file_format = FileFormatType::kPuffin ,
184- .partition = deletes->second .partition ,
185- .record_count = deletes->second .positions .Cardinality (),
186- .file_size_in_bytes = size,
187- // TODO(gangwu): support encryption key metadata
188- .referenced_data_file = std::string (referenced_data_file),
189- .content_offset = blob_metadata->second .offset ,
190- .content_size_in_bytes = blob_metadata->second .length ,
191- .partition_spec_id = deletes->second .spec
192- ? std::make_optional (deletes->second .spec ->spec_id ())
193- : std::nullopt ,
194- });
195- }
196-
197165 DVWriterOptions options_;
198166 std::map<std::string, Deletes, StringLess> deletes_by_path_;
199- std::map<std::string, puffin::BlobMetadata, StringLess> blobs_by_path_;
200167 DeleteWriteResult result_;
201168 bool closed_ = false ;
202169};
0 commit comments