From 9092c665b7f46190273e86dc1678642b2d484511 Mon Sep 17 00:00:00 2001 From: Charles Allen Date: Wed, 15 Jul 2015 16:58:15 -0700 Subject: [PATCH] Fix TopN dimension extractions being applied twice --- .../query/topn/TopNQueryQueryToolChest.java | 6 +- .../druid/query/topn/TopNQueryRunnerTest.java | 128 ++++++++++++++++++ 2 files changed, 129 insertions(+), 5 deletions(-) diff --git a/processing/src/main/java/io/druid/query/topn/TopNQueryQueryToolChest.java b/processing/src/main/java/io/druid/query/topn/TopNQueryQueryToolChest.java index 93e341d83c1..5d6b3e3974d 100644 --- a/processing/src/main/java/io/druid/query/topn/TopNQueryQueryToolChest.java +++ b/processing/src/main/java/io/druid/query/topn/TopNQueryQueryToolChest.java @@ -238,9 +238,6 @@ public class TopNQueryQueryToolChest extends QueryToolChest, Result>() { private String dimension = query.getDimensionSpec().getOutputName(); @@ -284,8 +281,7 @@ public class TopNQueryQueryToolChest extends QueryToolChestasList(QueryRunnerTestHelper.addRowsIndexConstant)) + .build(); + + List> expectedResults = Arrays.asList( + new Result<>( + new DateTime("2011-04-01T00:00:00.000Z"), + new TopNResultValue( + Arrays.>asList( + ImmutableMap.of( + QueryRunnerTestHelper.marketDimension, "2spot0", + "rows", 18L, + "index", 2231.8768157958984D, + "addRowsIndexConstant", 2250.8768157958984D, + "uniques", QueryRunnerTestHelper.UNIQUES_9 + ), + ImmutableMap.of( + QueryRunnerTestHelper.marketDimension, "1total_market0", + "rows", 4L, + "index", 5351.814697265625D, + "addRowsIndexConstant", 5356.814697265625D, + "uniques", QueryRunnerTestHelper.UNIQUES_2 + ), + ImmutableMap.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.asList(QueryRunnerTestHelper.addRowsIndexConstant)) + .build(); + + List> expectedResults = Arrays.asList( + new Result<>( + new DateTime("2011-04-01T00:00:00.000Z"), + new TopNResultValue( + Arrays.>asList( + ImmutableMap.of( + QueryRunnerTestHelper.marketDimension, "2spot0", + "rows", 18L, + "index", 2231.8768157958984D, + "addRowsIndexConstant", 2250.8768157958984D, + "uniques", QueryRunnerTestHelper.UNIQUES_9 + ), + ImmutableMap.of( + QueryRunnerTestHelper.marketDimension, "1total_market0", + "rows", 4L, + "index", 5351.814697265625D, + "addRowsIndexConstant", 5356.814697265625D, + "uniques", QueryRunnerTestHelper.UNIQUES_2 + ), + ImmutableMap.of( + QueryRunnerTestHelper.marketDimension, "3upfront0", + "rows", 4L, + "index", 4875.669677734375D, + "addRowsIndexConstant", 4880.669677734375D, + "uniques", QueryRunnerTestHelper.UNIQUES_2 + ) + ) + ) + ) + ); + assertExpectedResults(expectedResults, query); + } + + @Test // Test a "direct" query public void testTopNDimExtractionFastTopNOptimal()