Skip to content

Commit

Permalink
Fix NPE in TopNLexicographicResultBuilder.addEntry() (apache#2835)
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-wei authored and gianm committed Apr 14, 2016
1 parent 639d063 commit a261345
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public TopNResultBuilder addEntry(
public TopNResultBuilder addEntry(DimensionAndMetricValueExtractor dimensionAndMetricValueExtractor)
{
Object dimensionValueObj = dimensionAndMetricValueExtractor.getDimensionValue(dimSpec.getOutputName());
String dimensionValue = dimensionValueObj.toString();
String dimensionValue = dimensionValueObj == null ? null : dimensionValueObj.toString();

if (shouldAdd(dimensionValue)) {
pQueue.add(
Expand Down
59 changes: 59 additions & 0 deletions processing/src/test/java/io/druid/query/topn/TopNBinaryFnTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.junit.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -461,4 +462,62 @@ public void testMergeShiftedTimestamp()
Assert.assertEquals(expected.getTimestamp(), actual.getTimestamp());
assertTopNMergeResult(expected.getValue(), actual.getValue());
}

@Test
public void testMergeLexicographicWithInvalidDimName()
{
Result<TopNResultValue> result1 = new Result<TopNResultValue>(
currTime,
new TopNResultValue(
ImmutableList.<Map<String, Object>>of(
ImmutableMap.<String, Object>of(
"rows", 1L,
"index", 2L,
"testdim", "1"
)
)
)
);
Result<TopNResultValue> result2 = new Result<TopNResultValue>(
currTime,
new TopNResultValue(
ImmutableList.<Map<String, Object>>of(
ImmutableMap.<String, Object>of(
"rows", 2L,
"index", 3L,
"testdim", "1"
)
)
)
);

Map<String, Object> resultMap = new HashMap<>();
resultMap.put("INVALID_DIM_NAME", null);
resultMap.put("rows", 3L);
resultMap.put("index", 5L);

Result<TopNResultValue> expected = new Result<TopNResultValue>(
currTime,
new TopNResultValue(
ImmutableList.<Map<String, Object>>of(
resultMap
)
)
);

Result<TopNResultValue> actual = new TopNBinaryFn(
TopNResultMerger.identity,
QueryGranularity.ALL,
new DefaultDimensionSpec("INVALID_DIM_NAME", null),
new LexicographicTopNMetricSpec(null),
2,
aggregatorFactories,
postAggregators
).apply(
result1,
result2
);
Assert.assertEquals(expected.getTimestamp(), actual.getTimestamp());
assertTopNMergeResult(expected.getValue(), actual.getValue());
}
}

0 comments on commit a261345

Please sign in to comment.