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


##########
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) -> {
+          long v1 = o1.getCurrentPosition();
+          long v2 = o2.getCurrentPosition();
+          return Long.compare(v1, v2);
+        });
+        if (isPositionValid(records.get(0).getCurrentPosition())) {

Review Comment:
   There could inserts added to the log blocks, and inserts do not have current 
position, i.e., the record does not exist in the file group or base file.  
Since the records are sorted based on the positions, if the position of the 
first record is valid (>=0), then positions of all records are valid, i.e., 
non-negative.



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