mirror of https://github.com/apache/druid.git
Fix TopN dimension extractions being applied twice
This commit is contained in:
parent
850460446d
commit
9092c665b7
|
@ -238,9 +238,6 @@ public class TopNQueryQueryToolChest extends QueryToolChest<Result<TopNResultVal
|
||||||
final TopNQuery query, final MetricManipulationFn fn
|
final TopNQuery query, final MetricManipulationFn fn
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
final ExtractionFn extractionFn = TopNQueryEngine.canApplyExtractionInPost(query)
|
|
||||||
? query.getDimensionSpec().getExtractionFn()
|
|
||||||
: null;
|
|
||||||
return new Function<Result<TopNResultValue>, Result<TopNResultValue>>()
|
return new Function<Result<TopNResultValue>, Result<TopNResultValue>>()
|
||||||
{
|
{
|
||||||
private String dimension = query.getDimensionSpec().getOutputName();
|
private String dimension = query.getDimensionSpec().getOutputName();
|
||||||
|
@ -284,8 +281,7 @@ public class TopNQueryQueryToolChest extends QueryToolChest<Result<TopNResultVal
|
||||||
values.put(name, fn.manipulate(aggregatorFactories[i], input.getMetric(name)));
|
values.put(name, fn.manipulate(aggregatorFactories[i], input.getMetric(name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
final Object dimValue = input.getDimensionValue(dimension);
|
values.put(dimension, input.getDimensionValue(dimension));
|
||||||
values.put(dimension, extractionFn == null ? dimValue : extractionFn.apply(dimValue));
|
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1610,6 +1610,134 @@ public class TopNQueryRunnerTest
|
||||||
assertExpectedResults(expectedResults, query);
|
assertExpectedResults(expectedResults, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTopNDimExtractionFastTopNOptimalWithReplaceMissing()
|
||||||
|
{
|
||||||
|
TopNQuery query = new TopNQueryBuilder()
|
||||||
|
.dataSource(QueryRunnerTestHelper.dataSource)
|
||||||
|
.granularity(QueryRunnerTestHelper.allGran)
|
||||||
|
.dimension(
|
||||||
|
new ExtractionDimensionSpec(
|
||||||
|
QueryRunnerTestHelper.marketDimension,
|
||||||
|
QueryRunnerTestHelper.marketDimension,
|
||||||
|
new LookupExtractionFn(
|
||||||
|
new MapLookupExtractor(
|
||||||
|
ImmutableMap.of(
|
||||||
|
"spot", "2spot0",
|
||||||
|
"total_market", "1total_market0",
|
||||||
|
"upfront", "3upfront0"
|
||||||
|
)
|
||||||
|
), false, "MISSING", true
|
||||||
|
),
|
||||||
|
null
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.metric("rows")
|
||||||
|
.threshold(4)
|
||||||
|
.intervals(QueryRunnerTestHelper.firstToThird)
|
||||||
|
.aggregators(QueryRunnerTestHelper.commonAggregators)
|
||||||
|
.postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
List<Result<TopNResultValue>> expectedResults = Arrays.asList(
|
||||||
|
new Result<>(
|
||||||
|
new DateTime("2011-04-01T00:00:00.000Z"),
|
||||||
|
new TopNResultValue(
|
||||||
|
Arrays.<Map<String, Object>>asList(
|
||||||
|
ImmutableMap.<String, Object>of(
|
||||||
|
QueryRunnerTestHelper.marketDimension, "2spot0",
|
||||||
|
"rows", 18L,
|
||||||
|
"index", 2231.8768157958984D,
|
||||||
|
"addRowsIndexConstant", 2250.8768157958984D,
|
||||||
|
"uniques", QueryRunnerTestHelper.UNIQUES_9
|
||||||
|
),
|
||||||
|
ImmutableMap.<String, Object>of(
|
||||||
|
QueryRunnerTestHelper.marketDimension, "1total_market0",
|
||||||
|
"rows", 4L,
|
||||||
|
"index", 5351.814697265625D,
|
||||||
|
"addRowsIndexConstant", 5356.814697265625D,
|
||||||
|
"uniques", QueryRunnerTestHelper.UNIQUES_2
|
||||||
|
),
|
||||||
|
ImmutableMap.<String, Object>of(
|
||||||
|
QueryRunnerTestHelper.marketDimension, "3upfront0",
|
||||||
|
"rows", 4L,
|
||||||
|
"index", 4875.669677734375D,
|
||||||
|
"addRowsIndexConstant", 4880.669677734375D,
|
||||||
|
"uniques", QueryRunnerTestHelper.UNIQUES_2
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assertExpectedResults(expectedResults, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTopNDimExtractionFastTopNUnOptimalWithReplaceMissing()
|
||||||
|
{
|
||||||
|
TopNQuery query = new TopNQueryBuilder()
|
||||||
|
.dataSource(QueryRunnerTestHelper.dataSource)
|
||||||
|
.granularity(QueryRunnerTestHelper.allGran)
|
||||||
|
.dimension(
|
||||||
|
new ExtractionDimensionSpec(
|
||||||
|
QueryRunnerTestHelper.marketDimension,
|
||||||
|
QueryRunnerTestHelper.marketDimension,
|
||||||
|
new LookupExtractionFn(
|
||||||
|
new MapLookupExtractor(
|
||||||
|
ImmutableMap.of(
|
||||||
|
"spot", "2spot0",
|
||||||
|
"total_market", "1total_market0",
|
||||||
|
"upfront", "3upfront0"
|
||||||
|
)
|
||||||
|
), false, "MISSING", false
|
||||||
|
),
|
||||||
|
null
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.metric("rows")
|
||||||
|
.threshold(4)
|
||||||
|
.intervals(QueryRunnerTestHelper.firstToThird)
|
||||||
|
.aggregators(QueryRunnerTestHelper.commonAggregators)
|
||||||
|
.postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
List<Result<TopNResultValue>> expectedResults = Arrays.asList(
|
||||||
|
new Result<>(
|
||||||
|
new DateTime("2011-04-01T00:00:00.000Z"),
|
||||||
|
new TopNResultValue(
|
||||||
|
Arrays.<Map<String, Object>>asList(
|
||||||
|
ImmutableMap.<String, Object>of(
|
||||||
|
QueryRunnerTestHelper.marketDimension, "2spot0",
|
||||||
|
"rows", 18L,
|
||||||
|
"index", 2231.8768157958984D,
|
||||||
|
"addRowsIndexConstant", 2250.8768157958984D,
|
||||||
|
"uniques", QueryRunnerTestHelper.UNIQUES_9
|
||||||
|
),
|
||||||
|
ImmutableMap.<String, Object>of(
|
||||||
|
QueryRunnerTestHelper.marketDimension, "1total_market0",
|
||||||
|
"rows", 4L,
|
||||||
|
"index", 5351.814697265625D,
|
||||||
|
"addRowsIndexConstant", 5356.814697265625D,
|
||||||
|
"uniques", QueryRunnerTestHelper.UNIQUES_2
|
||||||
|
),
|
||||||
|
ImmutableMap.<String, Object>of(
|
||||||
|
QueryRunnerTestHelper.marketDimension, "3upfront0",
|
||||||
|
"rows", 4L,
|
||||||
|
"index", 4875.669677734375D,
|
||||||
|
"addRowsIndexConstant", 4880.669677734375D,
|
||||||
|
"uniques", QueryRunnerTestHelper.UNIQUES_2
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assertExpectedResults(expectedResults, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
// Test a "direct" query
|
// Test a "direct" query
|
||||||
public void testTopNDimExtractionFastTopNOptimal()
|
public void testTopNDimExtractionFastTopNOptimal()
|
||||||
|
|
Loading…
Reference in New Issue