LakshSingla commented on code in PR #14475:
URL: https://github.com/apache/druid/pull/14475#discussion_r1240354450


##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/util/IntervalUtils.java:
##########
@@ -61,4 +64,20 @@ public static List<Interval> difference(final List<Interval> 
list1, final List<I
 
     return retVal;
   }
+
+  /**
+   * This method checks if the provided interval is aligned by the granularity 
provided and if it occupies exactly
+   * one "unit" of the granularity
+   * Note: ALL granularity isn't aligned to any interval, however this method 
is defines that ALL granularity matches
+   * an interval with boundary ({@code DateTimes.MIN}, {@code DateTimes.MAX})
+   */
+  public static boolean doesIntervalMatchesGranularity(final Interval 
interval, final Granularity granularity)
+  {
+    // AllGranularity needs special handling since AllGranularity#bucketStart 
always returns false
+    if (granularity instanceof AllGranularity) {
+      return (interval.getStartMillis() == DateTimes.MIN.getMillis())
+             && (interval.getEndMillis() == DateTimes.MAX.getMillis());
+    }
+    return granularity.isAligned(interval) && 
granularity.bucketEnd(interval.getStart()).equals(interval.getEnd());

Review Comment:
   The above suggestion won't hold true in case the `interval` is a multiple of 
the `granularity`. For example an interval like 
`doesIntervalMatchesGranularity("2022-01-01/2022-01-03", Granularities.MONTH)` 
would return true with `granularity.isAligned()`, however false with the 
current implementation which is the desired behavior.
   
   If we specify `PARTITIONED BY DAY`, we shouldn't allow an allocation of 2 
days, therefore we check the partition end as well.
   
   WDYT?



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