mirror of https://github.com/apache/druid.git
Fix NPE when subquery returns empty result
This commit is contained in:
parent
f2c1f798b9
commit
c88cb2af16
|
@ -126,8 +126,13 @@ public class IncrementalIndexStorageAdapter implements StorageAdapter
|
||||||
@Override
|
@Override
|
||||||
public Iterable<Cursor> makeCursors(final Filter filter, final Interval interval, final QueryGranularity gran)
|
public Iterable<Cursor> makeCursors(final Filter filter, final Interval interval, final QueryGranularity gran)
|
||||||
{
|
{
|
||||||
|
if (index.isEmpty()) {
|
||||||
|
return ImmutableList.of();
|
||||||
|
}
|
||||||
|
|
||||||
Interval actualIntervalTmp = interval;
|
Interval actualIntervalTmp = interval;
|
||||||
|
|
||||||
|
|
||||||
final Interval dataInterval = new Interval(getMinTime().getMillis(), gran.next(getMaxTime().getMillis()));
|
final Interval dataInterval = new Interval(getMinTime().getMillis(), gran.next(getMaxTime().getMillis()));
|
||||||
if (!actualIntervalTmp.overlaps(dataInterval)) {
|
if (!actualIntervalTmp.overlaps(dataInterval)) {
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
|
|
|
@ -103,6 +103,9 @@ public class QueryRunnerTestHelper
|
||||||
public static final QuerySegmentSpec fullOnInterval = new MultipleIntervalSegmentSpec(
|
public static final QuerySegmentSpec fullOnInterval = new MultipleIntervalSegmentSpec(
|
||||||
Arrays.asList(new Interval("1970-01-01T00:00:00.000Z/2020-01-01T00:00:00.000Z"))
|
Arrays.asList(new Interval("1970-01-01T00:00:00.000Z/2020-01-01T00:00:00.000Z"))
|
||||||
);
|
);
|
||||||
|
public static final QuerySegmentSpec emptyInterval = new MultipleIntervalSegmentSpec(
|
||||||
|
Arrays.asList(new Interval("2020-04-02T00:00:00.000Z/P1D"))
|
||||||
|
);
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Collection<?> makeQueryRunners(
|
public static Collection<?> makeQueryRunners(
|
||||||
|
|
|
@ -58,7 +58,9 @@ import org.joda.time.DateTime;
|
||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
import org.joda.time.Interval;
|
import org.joda.time.Interval;
|
||||||
import org.joda.time.Period;
|
import org.joda.time.Period;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
|
@ -910,6 +912,39 @@ public class GroupByQueryRunnerTest
|
||||||
TestHelper.assertExpectedObjects(expectedResults, results, "");
|
TestHelper.assertExpectedObjects(expectedResults, results, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEmptySubquery()
|
||||||
|
{
|
||||||
|
GroupByQuery subquery = GroupByQuery
|
||||||
|
.builder()
|
||||||
|
.setDataSource(QueryRunnerTestHelper.dataSource)
|
||||||
|
.setQuerySegmentSpec(QueryRunnerTestHelper.emptyInterval)
|
||||||
|
.setDimensions(Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("quality", "alias")))
|
||||||
|
.setAggregatorSpecs(
|
||||||
|
Arrays.<AggregatorFactory>asList(
|
||||||
|
QueryRunnerTestHelper.rowsCount,
|
||||||
|
new LongSumAggregatorFactory("idx", "index")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setGranularity(QueryRunnerTestHelper.dayGran)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
GroupByQuery query = GroupByQuery
|
||||||
|
.builder()
|
||||||
|
.setDataSource(subquery)
|
||||||
|
.setQuerySegmentSpec(QueryRunnerTestHelper.firstToThird)
|
||||||
|
.setAggregatorSpecs(
|
||||||
|
Arrays.<AggregatorFactory>asList(
|
||||||
|
new MaxAggregatorFactory("idx", "idx")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setGranularity(QueryRunnerTestHelper.dayGran)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Iterable<Row> results = runQuery(query);
|
||||||
|
Assert.assertFalse(results.iterator().hasNext());
|
||||||
|
}
|
||||||
|
|
||||||
private Iterable<Row> runQuery(GroupByQuery query)
|
private Iterable<Row> runQuery(GroupByQuery query)
|
||||||
{
|
{
|
||||||
QueryToolChest<Row, GroupByQuery> toolChest = factory.getToolchest();
|
QueryToolChest<Row, GroupByQuery> toolChest = factory.getToolchest();
|
||||||
|
|
Loading…
Reference in New Issue