yihua commented on code in PR #12594:
URL: https://github.com/apache/hudi/pull/12594#discussion_r1929384862


##########
hudi-common/src/main/java/org/apache/hudi/common/table/log/block/HoodieDataBlock.java:
##########
@@ -84,19 +86,32 @@ public HoodieDataBlock(List<HoodieRecord> records,
                          Map<FooterMetadataType, String> footer,
                          String keyFieldName) {
     super(header, footer, Option.empty(), Option.empty(), null, false);
-    if (shouldWriteRecordPositions) {
-      records.sort((o1, o2) -> {
-        long v1 = o1.getCurrentPosition();
-        long v2 = o2.getCurrentPosition();
-        return Long.compare(v1, v2);
-      });
-      if (isPositionValid(records.get(0).getCurrentPosition())) {
-        addRecordPositionsToHeader(
-            
records.stream().map(HoodieRecord::getCurrentPosition).collect(Collectors.toSet()),
-            records.size());
+    if (shouldWriteRecordPositions && !records.isEmpty()) {
+      String baseFileInstantTime = 
records.get(0).getCurrentBaseFileInstantTime();
+      for (HoodieRecord record : records) {
+        if 
(!baseFileInstantTime.equals(record.getCurrentBaseFileInstantTime())) {
+          baseFileInstantTime = EMPTY_STRING;
+          break;
+        }
+      }
+      if (StringUtils.isNullOrEmpty(baseFileInstantTime)) {
+        LOG.warn("Base file instant time of delete positions cannot be 
determined, possibly "
+            + "due to inserts or different base file instant times for the 
input records.");
       } else {
-        LOG.warn("There are records without valid positions. "
-            + "Skip writing record positions to the data block header.");
+        records.sort((o1, o2) -> {

Review Comment:
   This is refactored from the existing code.  The reason of sorting the 
records based on the positions is that the record positions are stored in a 
Roaring Bitmap which is a set-based data structure, not maintaining the order.  
Since the record serialized in the log block is not attached with the position, 
we have to sort the records so we can map the position to each record 
accurately when reading them.



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

Reply via email to