shuturmurgh commented on code in PR #18486:
URL: https://github.com/apache/pinot/pull/18486#discussion_r3240794292


##########
pinot-common/src/main/java/org/apache/pinot/common/utils/RetentionUtils.java:
##########
@@ -74,4 +103,46 @@ public static boolean isPurgeable(String tableNameWithType, 
SegmentZKMetadata se
     }
     return false;
   }
+
+  /**
+   * Parses {@link 
SegmentsValidationAndRetentionConfig#getRetentionTimeUnit()} and
+   * {@link SegmentsValidationAndRetentionConfig#getRetentionTimeValue()} into 
table data retention duration in
+   * milliseconds (same interpretation as controller time-based retention).
+   *
+   * @return millis, or empty if unset or not parseable
+   */
+  public static OptionalLong parseTableDataRetentionMillis(
+      @Nullable SegmentsValidationAndRetentionConfig validationConfig) {
+    if (validationConfig == null) {
+      return OptionalLong.empty();
+    }
+    String retentionTimeUnit = validationConfig.getRetentionTimeUnit();
+    String retentionTimeValue = validationConfig.getRetentionTimeValue();
+    if (StringUtils.isEmpty(retentionTimeUnit) || 
StringUtils.isEmpty(retentionTimeValue)) {
+      return OptionalLong.empty();
+    }
+    try {
+      return OptionalLong.of(TimeUnit.valueOf(retentionTimeUnit.toUpperCase())
+          .toMillis(Long.parseLong(retentionTimeValue)));
+    } catch (Exception e) {
+      return OptionalLong.empty();
+    }
+  }
+
+  /**
+   * End timestamp in epoch millis for retention comparison from segment file 
metadata, aligned with segment impl time
+   * interval when valid.
+   */
+  static long segmentMetadataEndTimeMillis(SegmentMetadata segmentMetadata) {
+    Interval interval = segmentMetadata.getTimeInterval();
+    if (interval != null && TimeUtils.isValidTimeInterval(interval)) {
+      return interval.getEndMillis();
+    }
+    TimeUnit timeUnit = segmentMetadata.getTimeUnit();

Review Comment:
   - `SegmentMetadataImpl` can fail to build `_timeInterval` while still having 
raw start/end/unit in some failure paths (`setTimeInfo` catches Exception and 
logs).



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