Jackie-Jiang commented on code in PR #9193:
URL: https://github.com/apache/pinot/pull/9193#discussion_r946176802


##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/TimeUtils.java:
##########
@@ -167,6 +169,44 @@ public static Long convertPeriodToMillis(String timeStr) {
     return millis;
   }
 
+  /**
+   * Returns the millisecond of the period since the @since millisecond
+   * For ex, getMillisFromPeriod("2d",
+   *  Clock.fixed(java.time.Instant.ofEpochMilli(1660054290324L), 
ZoneId.of("UTC"))) -> 1659881490324
+   * The milliseconds of 2d is 172800000 hence the millisecond of 2d since 
1660054290324 is
+   * 1660054290324 - 172800000 = 1659881490324
+   *
+   * @param timeStr string representing the duration
+   * @param since Clock representing the time from which the period needs to 
be computed
+   * @return the corresponding time converted to milliseconds
+   * @throws IllegalArgumentException if the string does not conform to the 
expected format
+   */
+  public static long getMillisFromPeriod(String timeStr, Clock since) {
+    long periodToMillis = convertPeriodToMillis(timeStr);
+    return since.millis() - periodToMillis;

Review Comment:
   Seems we want to go back a certain period from the passed in time. IMO this 
method is a little bit confusing, so suggest removing it and make the caller 
use `convertPeriodToMillis()` instead



##########
pinot-spi/src/main/java/org/apache/pinot/spi/stream/OffsetCriteria.java:
##########
@@ -148,6 +159,18 @@ public OffsetCriteria withOffsetAsPeriod(String 
periodString) {
       return _offsetCriteria;
     }
 
+    /**
+     * Builds an {@link OffsetCriteria} with {@link OffsetType} TIMESTAMP
+     * @param timestamp
+     * @return
+     */
+    public OffsetCriteria withOffsetAsTimestamp(String timestamp) {
+      Preconditions.checkNotNull(timestamp, "Must provide period string eg. 
10d, 4h30m etc");

Review Comment:
   Modify the exception message



##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/TimeUtils.java:
##########
@@ -189,6 +229,19 @@ public static String convertMillisToPeriod(Long millis) {
   public static boolean isPeriodValid(String timeStr) {
     try {
       PERIOD_FORMATTER.parsePeriod(timeStr);
+      long periodToMillis = convertPeriodToMillis(timeStr);
+      return periodToMillis >= 0;

Review Comment:
   Suggest not adding this extra check. Negative period should also be valid



##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/TimeUtils.java:
##########
@@ -167,6 +169,44 @@ public static Long convertPeriodToMillis(String timeStr) {
     return millis;
   }
 
+  /**
+   * Returns the millisecond of the period since the @since millisecond
+   * For ex, getMillisFromPeriod("2d",
+   *  Clock.fixed(java.time.Instant.ofEpochMilli(1660054290324L), 
ZoneId.of("UTC"))) -> 1659881490324
+   * The milliseconds of 2d is 172800000 hence the millisecond of 2d since 
1660054290324 is
+   * 1660054290324 - 172800000 = 1659881490324
+   *
+   * @param timeStr string representing the duration
+   * @param since Clock representing the time from which the period needs to 
be computed
+   * @return the corresponding time converted to milliseconds
+   * @throws IllegalArgumentException if the string does not conform to the 
expected format
+   */
+  public static long getMillisFromPeriod(String timeStr, Clock since) {
+    long periodToMillis = convertPeriodToMillis(timeStr);
+    return since.millis() - periodToMillis;
+  }
+
+  /**
+   * Converts a string representing the timestamp to corresponding 
milliseconds.
+   *
+   * @param timeStr string representing the timestamp in ISO 8601 format
+   * @return the corresponding time converted to milliseconds
+   * @throws IllegalArgumentException if the string does not conform to the 
expected format
+   */
+  public static Long convertDateTimeToMillis(String timeStr) {

Review Comment:
   ```suggestion
     public static Long convertTimestampToMillis(String timeStr) {
   ```



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to