Search in sources :

Example 6 with TopNQuery

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

the class ClientQuerySegmentWalkerTest method testTopNOnArraysUnknownStrings.

@Test
public void testTopNOnArraysUnknownStrings() {
    final TopNQuery query = (TopNQuery) new TopNQueryBuilder().dataSource(ARRAY_UNKNOWN).granularity(Granularities.ALL).intervals(Intervals.ONLY_ETERNITY).dimension(DefaultDimensionSpec.of("as")).metric("sum_n").threshold(1000).aggregators(new LongSumAggregatorFactory("sum_n", "n")).build().withId(DUMMY_QUERY_ID);
    // 'unknown' is treated as ColumnType.STRING. this might not always be the case, so this is a test case of wacky
    // behavior of sorts
    testQuery(query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of(new Object[] { 946684800000L, "4.0", 6L }, new Object[] { 946684800000L, "8.0", 4L }, new Object[] { 946684800000L, "2.0", 3L }, new Object[] { 946684800000L, "3.0", 3L }, new Object[] { 946684800000L, "6.0", 3L }, new Object[] { 946684800000L, "1.0", 1L }));
    Assert.assertEquals(1, scheduler.getTotalRun().get());
    Assert.assertEquals(1, scheduler.getTotalPrioritizedAndLaned().get());
    Assert.assertEquals(1, scheduler.getTotalAcquired().get());
    Assert.assertEquals(1, scheduler.getTotalReleased().get());
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) TopNQuery(org.apache.druid.query.topn.TopNQuery) Test(org.junit.Test)

Example 7 with TopNQuery

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

the class ClientQuerySegmentWalkerTest method testTopNOnArraysUnknownLongs.

@Test
public void testTopNOnArraysUnknownLongs() {
    final TopNQuery query = (TopNQuery) new TopNQueryBuilder().dataSource(ARRAY_UNKNOWN).granularity(Granularities.ALL).intervals(Intervals.ONLY_ETERNITY).dimension(DefaultDimensionSpec.of("al")).metric("sum_n").threshold(1000).aggregators(new LongSumAggregatorFactory("sum_n", "n")).build().withId(DUMMY_QUERY_ID);
    // 'unknown' is treated as ColumnType.STRING. this might not always be the case, so this is a test case of wacky
    // behavior of sorts
    testQuery(query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of(new Object[] { 946684800000L, "4", 6L }, new Object[] { 946684800000L, "8", 4L }, new Object[] { 946684800000L, "2", 3L }, new Object[] { 946684800000L, "3", 3L }, new Object[] { 946684800000L, "6", 3L }, new Object[] { 946684800000L, "1", 1L }));
    Assert.assertEquals(1, scheduler.getTotalRun().get());
    Assert.assertEquals(1, scheduler.getTotalPrioritizedAndLaned().get());
    Assert.assertEquals(1, scheduler.getTotalAcquired().get());
    Assert.assertEquals(1, scheduler.getTotalReleased().get());
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) TopNQuery(org.apache.druid.query.topn.TopNQuery) Test(org.junit.Test)

Example 8 with TopNQuery

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

the class ClientQuerySegmentWalkerTest method testTopNScanMultiValue.

@Test
public void testTopNScanMultiValue() {
    ScanQuery subquery = new Druids.ScanQueryBuilder().dataSource(MULTI).columns("s", "n").intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.ETERNITY))).legacy(false).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).build();
    final TopNQuery query = (TopNQuery) new TopNQueryBuilder().dataSource(new QueryDataSource(subquery)).granularity(Granularities.ALL).intervals(Intervals.ONLY_ETERNITY).dimension(DefaultDimensionSpec.of("s")).metric("sum_n").threshold(100).aggregators(new LongSumAggregatorFactory("sum_n", "n")).build().withId(DUMMY_QUERY_ID);
    testQuery(query, // GroupBy handles its own subqueries; only the inner one will go to the cluster.
    ImmutableList.of(ExpectedQuery.cluster(subquery.withId(DUMMY_QUERY_ID).withSubQueryId("1.1")), ExpectedQuery.local(query.withDataSource(InlineDataSource.fromIterable(ImmutableList.of(new Object[] { ImmutableList.of("a", "b"), 1 }, new Object[] { ImmutableList.of("a", "c"), 2 }, new Object[] { ImmutableList.of("b"), 3 }, new Object[] { ImmutableList.of("c"), 4 }), RowSignature.builder().add("s", null).add("n", null).build())))), ImmutableList.of(new Object[] { Intervals.ETERNITY.getStartMillis(), "c", 6L }, new Object[] { Intervals.ETERNITY.getStartMillis(), "b", 4L }, new Object[] { Intervals.ETERNITY.getStartMillis(), "a", 3L }));
    Assert.assertEquals(2, scheduler.getTotalRun().get());
    Assert.assertEquals(1, scheduler.getTotalPrioritizedAndLaned().get());
    Assert.assertEquals(2, scheduler.getTotalAcquired().get());
    Assert.assertEquals(2, scheduler.getTotalReleased().get());
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) QueryDataSource(org.apache.druid.query.QueryDataSource) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) ScanQuery(org.apache.druid.query.scan.ScanQuery) TopNQuery(org.apache.druid.query.topn.TopNQuery) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) Test(org.junit.Test)

Example 9 with TopNQuery

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

the class DummyStringVirtualColumnTest method testTopN.

private void testTopN(List<Segment> segments, boolean enableRowBasedMethods, boolean enableColumnBasedMethods) {
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(Granularities.ALL).dimension(VSTRING_DIM).metric(COUNT).threshold(1).aggregators(new CountAggregatorFactory(COUNT)).virtualColumns(new DummyStringVirtualColumn(QueryRunnerTestHelper.MARKET_DIMENSION, VSTRING_DIM, enableRowBasedMethods, enableColumnBasedMethods, false, true)).intervals("2000/2030").build();
    List rows = topNTestHelper.runQueryOnSegmentsObjs(segments, query).toList();
    List<Result<TopNResultValue>> expectedRows = Collections.singletonList(new Result<>(DateTimes.of("2011-01-12T00:00:00.000Z"), new TopNResultValue(Collections.<Map<String, Object>>singletonList(ImmutableMap.<String, Object>builder().put(COUNT, 1674L).put(VSTRING_DIM, "spot").build()))));
    TestHelper.assertExpectedResults(expectedRows, (List<Result<TopNResultValue>>) rows, "failed");
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) TopNResultValue(org.apache.druid.query.topn.TopNResultValue) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) TopNQuery(org.apache.druid.query.topn.TopNQuery) List(java.util.List) Result(org.apache.druid.query.Result)

Example 10 with TopNQuery

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

the class QuerySchedulerTest method testHiLoReleaseLaneWhenSequenceExplodes.

@Test
public void testHiLoReleaseLaneWhenSequenceExplodes() throws Exception {
    expected.expectMessage("exploded");
    expected.expect(ExecutionException.class);
    TopNQuery interactive = makeInteractiveQuery();
    ListenableFuture<?> future = executorService.submit(() -> {
        try {
            Query<?> scheduled = scheduler.prioritizeAndLaneQuery(QueryPlus.wrap(interactive), ImmutableSet.of());
            Assert.assertNotNull(scheduled);
            Sequence<Integer> underlyingSequence = makeExplodingSequence(10);
            underlyingSequence = Sequences.wrap(underlyingSequence, new SequenceWrapper() {

                @Override
                public void before() {
                    Assert.assertEquals(4, scheduler.getTotalAvailableCapacity());
                }
            });
            Sequence<Integer> results = scheduler.run(scheduled, underlyingSequence);
            consumeAndCloseSequence(results);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    });
    future.get();
}
Also used : SequenceWrapper(org.apache.druid.java.util.common.guava.SequenceWrapper) TopNQuery(org.apache.druid.query.topn.TopNQuery) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

TopNQuery (org.apache.druid.query.topn.TopNQuery)38 Test (org.junit.Test)28 TopNQueryBuilder (org.apache.druid.query.topn.TopNQueryBuilder)25 Result (org.apache.druid.query.Result)10 TopNResultValue (org.apache.druid.query.topn.TopNResultValue)10 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)9 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)9 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)8 QueryRunner (org.apache.druid.query.QueryRunner)6 DoubleMaxAggregatorFactory (org.apache.druid.query.aggregation.DoubleMaxAggregatorFactory)6 DoubleMinAggregatorFactory (org.apache.druid.query.aggregation.DoubleMinAggregatorFactory)6 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)6 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)6 TopNQueryConfig (org.apache.druid.query.topn.TopNQueryConfig)6 TopNQueryQueryToolChest (org.apache.druid.query.topn.TopNQueryQueryToolChest)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 FinalizeResultsQueryRunner (org.apache.druid.query.FinalizeResultsQueryRunner)5 TableDataSource (org.apache.druid.query.TableDataSource)5 ImmutableMap (com.google.common.collect.ImmutableMap)4