From e5fa8e0cb4f4d79e09d615a47b22e44460485e0a Mon Sep 17 00:00:00 2001 From: nishantmonu51 Date: Tue, 10 Feb 2015 10:14:54 +0530 Subject: [PATCH] Fix NPE for union queries filter non-existing datasources for union queries. handle review comment --- .../druid/timeline/UnionTimeLineLookup.java | 4 +- .../VersionedIntervalTimelineTest.java | 46 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/io/druid/timeline/UnionTimeLineLookup.java b/common/src/main/java/io/druid/timeline/UnionTimeLineLookup.java index c14fafeeb5c..3233b639b5a 100644 --- a/common/src/main/java/io/druid/timeline/UnionTimeLineLookup.java +++ b/common/src/main/java/io/druid/timeline/UnionTimeLineLookup.java @@ -18,6 +18,7 @@ package io.druid.timeline; import com.google.common.base.Function; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import io.druid.timeline.partition.PartitionHolder; import org.joda.time.Interval; @@ -29,7 +30,8 @@ public class UnionTimeLineLookup implements TimelineLoo public UnionTimeLineLookup(Iterable> delegates) { - this.delegates = delegates; + // delegate can be null in case there is no segment loaded for the dataSource on this node + this.delegates = Iterables.filter(delegates, Predicates.notNull()); } @Override diff --git a/common/src/test/java/io/druid/timeline/VersionedIntervalTimelineTest.java b/common/src/test/java/io/druid/timeline/VersionedIntervalTimelineTest.java index 3b55b17ea36..164d4d306a0 100644 --- a/common/src/test/java/io/druid/timeline/VersionedIntervalTimelineTest.java +++ b/common/src/test/java/io/druid/timeline/VersionedIntervalTimelineTest.java @@ -21,6 +21,7 @@ import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; import com.google.common.collect.Ordering; import com.google.common.collect.Sets; import com.metamx.common.Pair; @@ -1594,4 +1595,49 @@ public class VersionedIntervalTimelineTest { return new VersionedIntervalTimeline(Ordering.natural()); } + + @Test + public void testUnionTimeLineLookup() + { + TimelineLookup lookup = new UnionTimeLineLookup( + Arrays.>asList( + timeline, + timeline + ) + ); + 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-06/2011-04-09", "3", 4) + ), + (List)Lists.newArrayList(lookup.lookup(new Interval("2011-04-01/2011-04-09"))) + ); + } + + @Test + public void testUnionTimeLineLookupNonExistentDelegates() + { + TimelineLookup lookup = new UnionTimeLineLookup( + Arrays.>asList( + timeline, + null, + timeline, + null + ) + ); + 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-06/2011-04-09", "3", 4) + ), + (List)Lists.newArrayList(lookup.lookup(new Interval("2011-04-01/2011-04-09"))) ); + } }