Merge pull request #1243 from metamx/fix-union-timeline-lookup

fixes TimeboundaryQuery and DataSourceMetadata queries returning wrong values for union queries
This commit is contained in:
Fangjin Yang 2015-03-26 10:02:56 -07:00
commit a9c47de571
4 changed files with 56 additions and 7 deletions

View File

@ -31,7 +31,7 @@ public interface TimelineLookup<VersionType, ObjectType>
* @param interval interval to find objects for
*
* @return Holders representing the interval that the objects exist for, PartitionHolders
* are guaranteed to be complete
* are guaranteed to be complete. Holders returned sorted by the interval.
*/
public Iterable<TimelineObjectHolder<VersionType, ObjectType>> lookup(Interval interval);

View File

@ -20,9 +20,12 @@ package io.druid.timeline;
import com.google.common.base.Function;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.metamx.common.guava.Comparators;
import io.druid.timeline.partition.PartitionHolder;
import org.joda.time.Interval;
import java.util.Comparator;
public class UnionTimeLineLookup<VersionType, ObjectType> implements TimelineLookup<VersionType, ObjectType>
{
@ -37,7 +40,7 @@ public class UnionTimeLineLookup<VersionType, ObjectType> implements TimelineLoo
@Override
public Iterable<TimelineObjectHolder<VersionType, ObjectType>> lookup(final Interval interval)
{
return Iterables.concat(
return Iterables.mergeSorted(
Iterables.transform(
delegates,
new Function<TimelineLookup<VersionType, ObjectType>, Iterable<TimelineObjectHolder<VersionType, ObjectType>>>()
@ -48,7 +51,17 @@ public class UnionTimeLineLookup<VersionType, ObjectType> implements TimelineLoo
return input.lookup(interval);
}
}
)
),
new Comparator<TimelineObjectHolder<VersionType, ObjectType>>()
{
@Override
public int compare(
TimelineObjectHolder<VersionType, ObjectType> o1, TimelineObjectHolder<VersionType, ObjectType> o2
)
{
return Comparators.intervalsByStartThenEnd().compare(o1.getInterval(), o2.getInterval());
}
}
);
}

View File

@ -1608,10 +1608,10 @@ public class VersionedIntervalTimelineTest
assertValues(
Arrays.asList(
createExpected("2011-04-01/2011-04-02", "3", 5),
createExpected("2011-04-02/2011-04-06", "2", 1),
createExpected("2011-04-06/2011-04-09", "3", 4),
createExpected("2011-04-01/2011-04-02", "3", 5),
createExpected("2011-04-02/2011-04-06", "2", 1),
createExpected("2011-04-02/2011-04-06", "2", 1),
createExpected("2011-04-06/2011-04-09", "3", 4),
createExpected("2011-04-06/2011-04-09", "3", 4)
),
(List)Lists.newArrayList(lookup.lookup(new Interval("2011-04-01/2011-04-09")))
@ -1632,12 +1632,43 @@ public class VersionedIntervalTimelineTest
assertValues(
Arrays.asList(
createExpected("2011-04-01/2011-04-02", "3", 5),
createExpected("2011-04-02/2011-04-06", "2", 1),
createExpected("2011-04-06/2011-04-09", "3", 4),
createExpected("2011-04-01/2011-04-02", "3", 5),
createExpected("2011-04-02/2011-04-06", "2", 1),
createExpected("2011-04-02/2011-04-06", "2", 1),
createExpected("2011-04-06/2011-04-09", "3", 4),
createExpected("2011-04-06/2011-04-09", "3", 4)
),
(List)Lists.newArrayList(lookup.lookup(new Interval("2011-04-01/2011-04-09"))) );
}
@Test
public void testUnionTimeLineLookupReturnsSortedValues()
{
timeline = makeStringIntegerTimeline();
add("2011-04-02/2011-04-06", "1", 1);
add("2011-04-03/2011-04-09", "9", 2);
VersionedIntervalTimeline t1 = timeline;
timeline = makeStringIntegerTimeline();
add("2011-04-01/2011-04-03", "2", 1);
add("2011-04-03/2011-04-10", "8", 2);
VersionedIntervalTimeline t2 = timeline;
TimelineLookup<String, Integer> lookup = new UnionTimeLineLookup<String, Integer>(
Arrays.<TimelineLookup<String, Integer>>asList(
t1, t2
)
);
assertValues(
Arrays.asList(
createExpected("2011-04-01/2011-04-03", "2", 1),
createExpected("2011-04-02/2011-04-03", "1", 1),
createExpected("2011-04-03/2011-04-09", "9", 2),
createExpected("2011-04-03/2011-04-10", "8", 2)
),
(List) Lists.newArrayList(lookup.lookup(new Interval("2011-04-01/2011-04-11")))
);
}
}

View File

@ -76,6 +76,11 @@ public abstract class QueryToolChest<ResultType, QueryType extends Query<ResultT
return runner;
}
/**
* @param query
* @param segments list of segments sorted by segment intervals.
* @return list of segments to be queried in order to determine query results.
*/
public <T extends LogicalSegment> List<T> filterSegments(QueryType query, List<T> segments)
{
return segments;