mirror of https://github.com/apache/druid.git
Fix NPE in TopNLexicographicResultBuilder.addEntry() (#2835)
This commit is contained in:
parent
639d0630b8
commit
a26134575b
|
@ -131,7 +131,7 @@ public class TopNLexicographicResultBuilder implements TopNResultBuilder
|
|||
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(
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.junit.Assert;
|
|||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -461,4 +462,62 @@ public class TopNBinaryFnTest
|
|||
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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue