wgtmac commented on code in PR #777:
URL: https://github.com/apache/iceberg-cpp/pull/777#discussion_r3484934756


##########
src/iceberg/data/delete_loader.cc:
##########
@@ -171,7 +177,44 @@ Status DeleteLoader::LoadPositionDelete(const DataFile& 
file, PositionDeleteInde
 }
 
 Status DeleteLoader::LoadDV(const DataFile& file, PositionDeleteIndex& index) 
const {
-  return NotSupported("Loading deletion vectors is not yet supported");
+  // A deletion vector must reference exactly one data file; without it the
+  // caller cannot know which data file the positions apply to.
+  ICEBERG_PRECHECK(file.referenced_data_file.has_value(),
+                   "Deletion vector requires referenced_data_file: {}", 
file.file_path);
+
+  // For deletion vectors, content_offset and content_size_in_bytes point 
directly
+  // at the DV blob bytes within the Puffin file and are required by the spec.
+  ICEBERG_PRECHECK(
+      file.content_offset.has_value() && 
file.content_size_in_bytes.has_value(),
+      "Deletion vector requires content_offset and content_size_in_bytes: {}",
+      file.file_path);
+
+  const int64_t offset = file.content_offset.value();
+  const int64_t length = file.content_size_in_bytes.value();
+  ICEBERG_PRECHECK(offset >= 0 && length >= 0,
+                   "Invalid deletion vector offset/length: offset={}, 
length={}", offset,
+                   length);
+  ICEBERG_PRECHECK(length <= std::numeric_limits<int32_t>::max(),
+                   "Cannot read deletion vector larger than 2GB: {}", length);
+
+  ICEBERG_ASSIGN_OR_RAISE(auto input_file, io_->NewInputFile(file.file_path));
+  ICEBERG_ASSIGN_OR_RAISE(auto stream, input_file->Open());
+
+  std::vector<std::byte> bytes(static_cast<size_t>(length));
+  ICEBERG_RETURN_UNEXPECTED(stream->ReadFully(offset, bytes));
+  ICEBERG_RETURN_UNEXPECTED(stream->Close());
+
+  std::span<const uint8_t> blob(reinterpret_cast<const uint8_t*>(bytes.data()),
+                                bytes.size());
+  ICEBERG_ASSIGN_OR_RAISE(auto bitmap, 
puffin::DeserializeDeletionVectorBlob(blob));

Review Comment:
   Please keep the source delete file with the loaded index. Java 
PositionDeleteIndex.deserialize(bytes, deleteFile) preserves it, and 
BaseDVFileWriter uses deleteFiles() to fill rewrittenDeleteFiles after merging 
old deletes.



-- 
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]

Reply via email to