diff --git a/processing/src/main/java/io/druid/query/timeboundary/TimeBoundaryQuery.java b/processing/src/main/java/io/druid/query/timeboundary/TimeBoundaryQuery.java index 7e93a2aae74..92770e69fb9 100644 --- a/processing/src/main/java/io/druid/query/timeboundary/TimeBoundaryQuery.java +++ b/processing/src/main/java/io/druid/query/timeboundary/TimeBoundaryQuery.java @@ -176,11 +176,11 @@ public class TimeBoundaryQuery extends BaseQuery final DateTime minTime; final DateTime maxTime; - if (bound.equalsIgnoreCase(MIN_TIME)) { + if (isMinTime()) { ts = min; minTime = min; maxTime = null; - } else if (bound.equalsIgnoreCase(MAX_TIME)) { + } else if (isMaxTime()) { ts = max; minTime = null; maxTime = max; @@ -193,6 +193,16 @@ public class TimeBoundaryQuery extends BaseQuery return buildResult(ts, minTime, maxTime); } + boolean isMinTime() + { + return bound.equalsIgnoreCase(MIN_TIME); + } + + boolean isMaxTime() + { + return bound.equalsIgnoreCase(MAX_TIME); + } + @Override public String toString() { diff --git a/processing/src/main/java/io/druid/query/timeboundary/TimeBoundaryQueryQueryToolChest.java b/processing/src/main/java/io/druid/query/timeboundary/TimeBoundaryQueryQueryToolChest.java index 727e4174db1..3c74eabf24c 100644 --- a/processing/src/main/java/io/druid/query/timeboundary/TimeBoundaryQueryQueryToolChest.java +++ b/processing/src/main/java/io/druid/query/timeboundary/TimeBoundaryQueryQueryToolChest.java @@ -65,8 +65,8 @@ public class TimeBoundaryQueryQueryToolChest return segments; } - final T min = segments.get(0); - final T max = segments.get(segments.size() - 1); + final T min = query.isMaxTime() ? null : segments.get(0); + final T max = query.isMinTime() ? null : segments.get(segments.size() - 1); return Lists.newArrayList( Iterables.filter( diff --git a/processing/src/test/java/io/druid/query/timeboundary/TimeBoundaryQueryQueryToolChestTest.java b/processing/src/test/java/io/druid/query/timeboundary/TimeBoundaryQueryQueryToolChestTest.java index e23e23e1d8d..94798445700 100644 --- a/processing/src/test/java/io/druid/query/timeboundary/TimeBoundaryQueryQueryToolChestTest.java +++ b/processing/src/test/java/io/druid/query/timeboundary/TimeBoundaryQueryQueryToolChestTest.java @@ -40,66 +40,66 @@ import java.util.List; */ public class TimeBoundaryQueryQueryToolChestTest { + + private static final TimeBoundaryQuery TIME_BOUNDARY_QUERY = new TimeBoundaryQuery( + new TableDataSource("test"), + null, + null, + null + ); + + private static final TimeBoundaryQuery MAXTIME_BOUNDARY_QUERY = new TimeBoundaryQuery( + new TableDataSource("test"), + null, + TimeBoundaryQuery.MAX_TIME, + null + ); + + private static final TimeBoundaryQuery MINTIME_BOUNDARY_QUERY = new TimeBoundaryQuery( + new TableDataSource("test"), + null, + TimeBoundaryQuery.MIN_TIME, + null + ); + + + private static LogicalSegment createLogicalSegment(final Interval interval) + { + return new LogicalSegment() + { + @Override + public Interval getInterval() + { + return interval; + } + }; + } + @Test public void testFilterSegments() throws Exception { List segments = new TimeBoundaryQueryQueryToolChest().filterSegments( - null, + TIME_BOUNDARY_QUERY, Arrays.asList( - new LogicalSegment() - { - @Override - public Interval getInterval() - { - return new Interval("2013-01-01/P1D"); - } - }, - new LogicalSegment() - { - @Override - public Interval getInterval() - { - return new Interval("2013-01-01T01/PT1H"); - } - }, - new LogicalSegment() - { - @Override - public Interval getInterval() - { - return new Interval("2013-01-01T02/PT1H"); - } - } + createLogicalSegment(new Interval("2013-01-01/P1D")), + createLogicalSegment(new Interval("2013-01-01T01/PT1H")), + createLogicalSegment(new Interval("2013-01-01T02/PT1H")), + createLogicalSegment(new Interval("2013-01-02/P1D")), + createLogicalSegment(new Interval("2013-01-03T01/PT1H")), + createLogicalSegment(new Interval("2013-01-03T02/PT1H")), + createLogicalSegment(new Interval("2013-01-03/P1D")) ) ); - Assert.assertEquals(segments.size(), 3); + Assert.assertEquals(6, segments.size()); List expected = Arrays.asList( - new LogicalSegment() - { - @Override - public Interval getInterval() - { - return new Interval("2013-01-01/P1D"); - } - }, - new LogicalSegment() - { - @Override - public Interval getInterval() - { - return new Interval("2013-01-01T01/PT1H"); - } - }, - new LogicalSegment() - { - @Override - public Interval getInterval() - { - return new Interval("2013-01-01T02/PT1H"); - } - } + createLogicalSegment(new Interval("2013-01-01/P1D")), + createLogicalSegment(new Interval("2013-01-01T01/PT1H")), + createLogicalSegment(new Interval("2013-01-01T02/PT1H")), + createLogicalSegment(new Interval("2013-01-03T01/PT1H")), + createLogicalSegment(new Interval("2013-01-03T02/PT1H")), + createLogicalSegment(new Interval("2013-01-03/P1D")) ); for (int i = 0; i < segments.size(); i++) { @@ -107,6 +107,64 @@ public class TimeBoundaryQueryQueryToolChestTest } } + @Test + public void testMaxTimeFilterSegments() throws Exception + { + List segments = new TimeBoundaryQueryQueryToolChest().filterSegments( + MAXTIME_BOUNDARY_QUERY, + Arrays.asList( + createLogicalSegment(new Interval("2013-01-01/P1D")), + createLogicalSegment(new Interval("2013-01-01T01/PT1H")), + createLogicalSegment(new Interval("2013-01-01T02/PT1H")), + createLogicalSegment(new Interval("2013-01-02/P1D")), + createLogicalSegment(new Interval("2013-01-03T01/PT1H")), + createLogicalSegment(new Interval("2013-01-03T02/PT1H")), + createLogicalSegment(new Interval("2013-01-03/P1D")) + ) + ); + + Assert.assertEquals(3, segments.size()); + + List expected = Arrays.asList( + createLogicalSegment(new Interval("2013-01-03T01/PT1H")), + createLogicalSegment(new Interval("2013-01-03T02/PT1H")), + createLogicalSegment(new Interval("2013-01-03/P1D")) + ); + + for (int i = 0; i < segments.size(); i++) { + Assert.assertEquals(segments.get(i).getInterval(), expected.get(i).getInterval()); + } + } + + @Test + public void testMinTimeFilterSegments() throws Exception + { + List segments = new TimeBoundaryQueryQueryToolChest().filterSegments( + MINTIME_BOUNDARY_QUERY, + Arrays.asList( + createLogicalSegment(new Interval("2013-01-01/P1D")), + createLogicalSegment(new Interval("2013-01-01T01/PT1H")), + createLogicalSegment(new Interval("2013-01-01T02/PT1H")), + createLogicalSegment(new Interval("2013-01-02/P1D")), + createLogicalSegment(new Interval("2013-01-03T01/PT1H")), + createLogicalSegment(new Interval("2013-01-03T02/PT1H")), + createLogicalSegment(new Interval("2013-01-03/P1D")) + ) + ); + + Assert.assertEquals(3, segments.size()); + + List expected = Arrays.asList( + createLogicalSegment(new Interval("2013-01-01/P1D")), + createLogicalSegment(new Interval("2013-01-01T01/PT1H")), + createLogicalSegment(new Interval("2013-01-01T02/PT1H")) + ); + + for (int i = 0; i < segments.size(); i++) { + Assert.assertEquals(segments.get(i).getInterval(), expected.get(i).getInterval()); + } + } + @Test public void testCacheStrategy() throws Exception {