Search in sources :

Example 51 with Result

use of org.apache.druid.query.Result in project druid by druid-io.

the class TopNQueryRunnerTest method testTopNWithExtractionFilter.

@Test
public void testTopNWithExtractionFilter() {
    Map<String, String> extractionMap = new HashMap<>();
    extractionMap.put("spot", "spot0");
    MapLookupExtractor mapLookupExtractor = new MapLookupExtractor(extractionMap, false);
    LookupExtractionFn lookupExtractionFn = new LookupExtractionFn(mapLookupExtractor, false, null, true, false);
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(QueryRunnerTestHelper.MARKET_DIMENSION).metric("rows").threshold(3).intervals(QueryRunnerTestHelper.FIRST_TO_THIRD).aggregators(commonAggregators).postAggregators(QueryRunnerTestHelper.ADD_ROWS_INDEX_CONSTANT).filters(new ExtractionDimFilter(QueryRunnerTestHelper.MARKET_DIMENSION, "spot0", lookupExtractionFn, null)).build();
    List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-04-01T00:00:00.000Z"), new TopNResultValue(Collections.<Map<String, Object>>singletonList(ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "spot", "rows", 18L, "index", 2231.876812D, "addRowsIndexConstant", 2250.876812D, "uniques", QueryRunnerTestHelper.UNIQUES_9)))));
    assertExpectedResults(expectedResults, query);
    // Assert the optimization path as well
    final Sequence<Result<TopNResultValue>> retval = runWithPreMergeAndMerge(query);
    TestHelper.assertExpectedResults(expectedResults, retval);
}
Also used : HashMap(java.util.HashMap) ExtractionDimFilter(org.apache.druid.query.filter.ExtractionDimFilter) Result(org.apache.druid.query.Result) LookupExtractionFn(org.apache.druid.query.lookup.LookupExtractionFn) MapLookupExtractor(org.apache.druid.query.extraction.MapLookupExtractor) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 52 with Result

use of org.apache.druid.query.Result in project druid by druid-io.

the class TopNQueryRunnerTest method testSortOnDoubleAsLong.

@Test
public void testSortOnDoubleAsLong() {
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(new DefaultDimensionSpec("index", "index_alias", ColumnType.LONG)).metric(new DimensionTopNMetricSpec(null, StringComparators.NUMERIC)).threshold(4).intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).build();
    List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-01-12T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>builder().put("index_alias", 59L).build(), ImmutableMap.<String, Object>builder().put("index_alias", 67L).build(), ImmutableMap.<String, Object>builder().put("index_alias", 68L).build(), ImmutableMap.<String, Object>builder().put("index_alias", 69L).build()))));
    assertExpectedResults(expectedResults, query);
}
Also used : DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 53 with Result

use of org.apache.druid.query.Result in project druid by druid-io.

the class TopNQueryRunnerTest method testTopNLexicographicDimExtractionOptimalNamespaceWithRunner.

@Test
public void testTopNLexicographicDimExtractionOptimalNamespaceWithRunner() {
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.MARKET_DIMENSION, QueryRunnerTestHelper.MARKET_DIMENSION, new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("spot", "2spot", "total_market", "3total_market", "upfront", "1upfront"), false), true, null, true, false))).metric(new DimensionTopNMetricSpec(null, StringComparators.LEXICOGRAPHIC)).threshold(4).intervals(QueryRunnerTestHelper.FIRST_TO_THIRD).aggregators(commonAggregators).postAggregators(QueryRunnerTestHelper.ADD_ROWS_INDEX_CONSTANT).build();
    List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "1upfront", "rows", 4L, "index", 4875.669692D, "addRowsIndexConstant", 4880.669692D, "uniques", QueryRunnerTestHelper.UNIQUES_2), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "2spot", "rows", 18L, "index", 2231.876812D, "addRowsIndexConstant", 2250.876812D, "uniques", QueryRunnerTestHelper.UNIQUES_9), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "3total_market", "rows", 4L, "index", 5351.814783D, "addRowsIndexConstant", 5356.814783D, "uniques", QueryRunnerTestHelper.UNIQUES_2)))));
    assertExpectedResults(expectedResults, query);
}
Also used : LookupExtractionFn(org.apache.druid.query.lookup.LookupExtractionFn) MapLookupExtractor(org.apache.druid.query.extraction.MapLookupExtractor) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 54 with Result

use of org.apache.druid.query.Result in project druid by druid-io.

the class TopNQueryRunnerTest method testInvertedTopNLexicographicDimExtraction2.

@Test
public void testInvertedTopNLexicographicDimExtraction2() {
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.MARKET_DIMENSION, QueryRunnerTestHelper.MARKET_DIMENSION, new RegexDimExtractionFn("..(.)", false, null))).metric(new InvertedTopNMetricSpec(new DimensionTopNMetricSpec(null, StringComparators.LEXICOGRAPHIC))).threshold(4).intervals(QueryRunnerTestHelper.FIRST_TO_THIRD).aggregators(commonAggregators).postAggregators(QueryRunnerTestHelper.ADD_ROWS_INDEX_CONSTANT).build();
    List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "t", "rows", 4L, "index", 5351.814783D, "addRowsIndexConstant", 5356.814783D, "uniques", QueryRunnerTestHelper.UNIQUES_2), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "o", "rows", 18L, "index", 2231.876812D, "addRowsIndexConstant", 2250.876812D, "uniques", QueryRunnerTestHelper.UNIQUES_9), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "f", "rows", 4L, "index", 4875.669692D, "addRowsIndexConstant", 4880.669692D, "uniques", QueryRunnerTestHelper.UNIQUES_2)))));
    assertExpectedResults(expectedResults, query);
}
Also used : RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 55 with Result

use of org.apache.druid.query.Result in project druid by druid-io.

the class TopNQueryRunnerTest method testAggregateOnDoubleNumericNull.

@Test
public void testAggregateOnDoubleNumericNull() {
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(new DefaultDimensionSpec("doubleNumericNull", "dim", ColumnType.DOUBLE)).metric(new DimensionTopNMetricSpec(null, StringComparators.NUMERIC)).threshold(10000).aggregators(new CountAggregatorFactory("count")).intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).build();
    List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-01-12T00:00:00.000Z"), new TopNResultValue(Arrays.asList(makeRowWithNulls("dim", NullHandling.defaultDoubleValue(), "count", 279L), makeRowWithNulls("dim", 10.0, "count", 93L), makeRowWithNulls("dim", 20.0, "count", 93L), makeRowWithNulls("dim", 40.0, "count", 93L), makeRowWithNulls("dim", 50.0, "count", 279L), makeRowWithNulls("dim", 70.0, "count", 279L), makeRowWithNulls("dim", 80.0, "count", 93L)))));
    assertExpectedResults(expectedResults, query);
}
Also used : CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

Result (org.apache.druid.query.Result)252 Test (org.junit.Test)181 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)143 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)46 TimeseriesResultValue (org.apache.druid.query.timeseries.TimeseriesResultValue)44 TimeseriesQuery (org.apache.druid.query.timeseries.TimeseriesQuery)41 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)40 QueryRunner (org.apache.druid.query.QueryRunner)37 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)36 DoubleMaxAggregatorFactory (org.apache.druid.query.aggregation.DoubleMaxAggregatorFactory)34 DoubleMinAggregatorFactory (org.apache.druid.query.aggregation.DoubleMinAggregatorFactory)34 ArrayList (java.util.ArrayList)33 FinalizeResultsQueryRunner (org.apache.druid.query.FinalizeResultsQueryRunner)32 ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)32 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)31 TopNResultValue (org.apache.druid.query.topn.TopNResultValue)28 DateTime (org.joda.time.DateTime)28 Benchmark (org.openjdk.jmh.annotations.Benchmark)28 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)28 OutputTimeUnit (org.openjdk.jmh.annotations.OutputTimeUnit)28