kfaraz commented on code in PR #18477:
URL: https://github.com/apache/druid/pull/18477#discussion_r2320811376


##########
processing/src/main/java/org/apache/druid/java/util/common/Intervals.java:
##########
@@ -53,6 +57,46 @@ public static Interval of(String format, Object... 
formatArgs)
     return of(StringUtils.format(format, formatArgs));
   }
 
+  /**
+   * @return Null if cannot parse with optimized strategy, else return the 
Interval.

Review Comment:
   For what kind of interval strings does this method return null?
   
   Is there a simpler way to short circuit in those cases rather than trying 
the parse unnecessarily?\
   Maybe a `canDeserializeOptimally()` method which checks it upfront?



##########
processing/src/main/java/org/apache/druid/java/util/common/Intervals.java:
##########
@@ -53,6 +57,46 @@ public static Interval of(String format, Object... 
formatArgs)
     return of(StringUtils.format(format, formatArgs));
   }
 
+  /**
+   * @return Null if cannot parse with optimized strategy, else return the 
Interval.

Review Comment:
   ```suggestion
      * @return null if cannot parse with optimized strategy, else return the 
Interval.
   ```



##########
processing/src/main/java/org/apache/druid/java/util/common/Intervals.java:
##########
@@ -53,6 +57,46 @@ public static Interval of(String format, Object... 
formatArgs)
     return of(StringUtils.format(format, formatArgs));
   }
 
+  /**
+   * @return Null if cannot parse with optimized strategy, else return the 
Interval.
+   */
+  @Nullable
+  private static Interval tryOptimizedIntervalDeserialization(final String 
intervalText)
+  {
+    final int slashIndex = intervalText.indexOf('/');
+    if (slashIndex <= 0 || slashIndex >= intervalText.length() - 1) {
+      return null;
+    }
+    try {
+      final String startStr = intervalText.substring(0, slashIndex);
+      final long startMillis = FAST_ISO_UTC_FORMATTER.parseMillis(startStr);
+
+      final String endStr = intervalText.substring(slashIndex + 1);
+      final long endMillis = FAST_ISO_UTC_FORMATTER.parseMillis(endStr);
+      return Intervals.utc(startMillis, endMillis);
+    }
+    catch (IllegalArgumentException e) {
+      return null;
+    }
+  }
+
+  /**
+   * Parses a Joda-Time {@link Interval} from its string representation.
+   *
+   * Tries a fast path for ISO-8601 UTC, slash-delimited intervals (e.g.
+   * "2022-09-16T00:00:00.000Z/2022-09-17T00:00:00.000Z"); otherwise falls 
back to the
+   * general interval parser. The returned interval uses ISO chronology in UTC.
+   */
+  public static Interval deserialize(String string)

Review Comment:
   ```suggestion
     public static Interval fromString(String string)
   ```



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