You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "kfaraz (via GitHub)" <gi...@apache.org> on 2023/04/21 11:22:30 UTC
[GitHub] [druid] kfaraz commented on a diff in pull request #14136: Improved handling for zero-length intervals.
kfaraz commented on code in PR #14136:
URL: https://github.com/apache/druid/pull/14136#discussion_r1173649694
##########
processing/src/main/java/org/apache/druid/java/util/common/JodaUtils.java:
##########
@@ -69,30 +71,39 @@ public static List<Interval> condenseIntervals(Iterable<Interval> intervals)
}
/**
- * This method does not materialize the intervals represented by the
- * sortedIntervals iterator. However, caller needs to insure that sortedIntervals
- * is already sorted in ascending order (use the Comparators.intervalsByStartThenEnd()).
- * It avoids materialization by incrementally condensing the intervals by
+ * Condense the provided intervals such that the returned list has no abutting intervals, no overlapping intervals,
+ * and no zero-length intervals.
+ * <p>
+ * The provided intervals must be sorted in ascending order using {@link Comparators#intervalsByStartThenEnd()}.
+ * Otherwise, results are undefined.
+ * <p>
+ * The method avoids materialization by incrementally condensing the intervals by
* starting from the first and looking for "adjacent" intervals. This is
* possible since intervals in the Iterator are in ascending order (as
* guaranteed by the caller).
- * <p>
- * *
*
* @param sortedIntervals The iterator object containing the intervals to condense
+ *
* @return An iterator for the condensed intervals. By construction the condensed intervals are sorted
* in ascending order and contain no repeated elements. The iterator can contain nulls,
* they will be skipped if it does.
+ *
* @throws IAE if an element is null or if sortedIntervals is not sorted in ascending order
*/
public static Iterator<Interval> condensedIntervalsIterator(Iterator<Interval> sortedIntervals)
{
-
if (sortedIntervals == null || !sortedIntervals.hasNext()) {
return Collections.emptyIterator();
}
- final PeekingIterator<Interval> peekingIterator = Iterators.peekingIterator(sortedIntervals);
+ final PeekingIterator<Interval> peekingIterator =
+ Iterators.peekingIterator(
+ Iterators.filter(
+ sortedIntervals,
+ interval -> interval == null || interval.toDurationMillis() > 0
Review Comment:
Why do we want to retain null intervals?
##########
processing/src/test/java/org/apache/druid/timeline/VersionedIntervalTimelineTest.java:
##########
@@ -470,6 +470,66 @@ public void testOverlapSecondContainsFirst()
);
}
+ // 1|----|----|
+ // 2|---------|
+ @Test
+ public void testOverlapSecondContainsFirstZeroLengthInterval()
+ {
+ add("2011-01-01/2011-01-20", "1", 1);
+ add("2011-01-01/2011-01-10", "2", 2);
+ add("2011-01-10/2011-01-20", "2", 3);
+
+ assertValues(
+ Collections.emptyList(),
+ timeline.lookup(Intervals.of("2011-01-10/2011-01-10"))
+ );
+ }
+
+ // 1|----|----|
+ // 2|---------|
+ @Test
+ public void testOverlapSecondContainsFirstZeroLengthInterval2()
+ {
+ add("2011-01-01/2011-01-20", "1", 1);
+ add("2011-01-01/2011-01-10", "2", 2);
+ add("2011-01-10/2011-01-20", "2", 3);
+
+ assertValues(
+ Collections.emptyList(),
+ timeline.lookup(Intervals.of("2011-01-11/2011-01-11"))
+ );
+ }
+
+ // 1|----|----|
+ // 2|---------|
+ @Test
+ public void testOverlapSecondContainsFirstZeroLengthInterval3()
+ {
+ add("2011-01-01/2011-01-20", "1", 1);
+ add("2011-01-01/2011-01-10", "2", 2);
+ add("2011-01-10/2011-01-20", "2", 3);
+
+ assertValues(
+ Collections.emptyList(),
+ timeline.lookup(Intervals.of("2011-01-01/2011-01-01"))
+ );
+ }
+
+ // 1|----|----|
+ // 2|---------|
+ @Test
+ public void testOverlapSecondContainsFirstZeroLengthInterval4()
Review Comment:
Are these tests meant to be duplicates of each other?
--
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-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org