fix npe in topNBinaryFn with post aggs

This commit is contained in:
Xavier Léauté 2014-04-21 22:15:11 -07:00
parent 310073685d
commit bbedde3418
2 changed files with 35 additions and 6 deletions

View File

@ -91,7 +91,19 @@ public class TopNBinaryFn implements BinaryFn<Result<TopNResultValue>, Result<To
String dimension = dimensionSpec.getOutputName();
for (DimensionAndMetricValueExtractor arg1Val : arg1Vals) {
retVals.put(arg1Val.getStringDimensionValue(dimension), arg1Val);
final String dimensionValue = arg1Val.getStringDimensionValue(dimension);
Map<String, Object> retVal = new LinkedHashMap<String, Object>(aggregations.size() + 2);
retVal.put(dimension, dimensionValue);
for (AggregatorFactory factory : aggregations) {
final String metricName = factory.getName();
retVal.put(metricName, arg1Val.getMetric(metricName));
}
for (PostAggregator postAgg : postAggregations) {
retVal.put(postAgg.getName(), postAgg.compute(retVal));
}
retVals.put(dimensionValue, new DimensionAndMetricValueExtractor(retVal));
}
for (DimensionAndMetricValueExtractor arg2Val : arg2Vals) {
final String dimensionValue = arg2Val.getStringDimensionValue(dimension);
@ -112,7 +124,18 @@ public class TopNBinaryFn implements BinaryFn<Result<TopNResultValue>, Result<To
retVals.put(dimensionValue, new DimensionAndMetricValueExtractor(retVal));
} else {
retVals.put(dimensionValue, arg2Val);
Map<String, Object> retVal = new LinkedHashMap<String, Object>(aggregations.size() + 2);
retVal.put(dimension, dimensionValue);
for (AggregatorFactory factory : aggregations) {
final String metricName = factory.getName();
retVal.put(metricName, arg2Val.getMetric(metricName));
}
for (PostAggregator postAgg : postAggregations) {
retVal.put(postAgg.getName(), postAgg.compute(retVal));
}
retVals.put(dimensionValue, new DimensionAndMetricValueExtractor(retVal));
}
}

View File

@ -324,9 +324,9 @@ public class TopNBinaryFnTest
"testdim", "2"
),
ImmutableMap.<String, Object>of(
"rows", 0L,
"index", 1L,
"testdim", "3"
"rows", 4L,
"index", 5L,
"testdim", "other"
)
)
)
@ -336,6 +336,12 @@ public class TopNBinaryFnTest
currTime,
new TopNResultValue(
ImmutableList.<Map<String, Object>>of(
ImmutableMap.<String, Object>of(
"testdim", "other",
"rows", 4L,
"index", 5L,
"addrowsindexconstant", 10.0
),
ImmutableMap.<String, Object>of(
"testdim", "1",
"rows", 3L,
@ -357,7 +363,7 @@ public class TopNBinaryFnTest
QueryGranularity.ALL,
new DefaultDimensionSpec("testdim", null),
new NumericTopNMetricSpec("addrowsindexconstant"),
2,
3,
aggregatorFactories,
postAggregators
).apply(