Search in sources :

Example 96 with Sequence

use of org.apache.druid.java.util.common.guava.Sequence in project druid by druid-io.

the class TimewarpOperatorTest method testPostProcessWithTimezonesAndNoDstShift.

@Test
public void testPostProcessWithTimezonesAndNoDstShift() {
    QueryRunner<Result<TimeseriesResultValue>> queryRunner = testOperator.postProcess(new QueryRunner<Result<TimeseriesResultValue>>() {

        @Override
        public Sequence<Result<TimeseriesResultValue>> run(QueryPlus<Result<TimeseriesResultValue>> queryPlus, ResponseContext responseContext) {
            return Sequences.simple(ImmutableList.of(new Result<>(DateTimes.of("2014-01-09T-07"), new TimeseriesResultValue(ImmutableMap.of("metric", 2))), new Result<>(DateTimes.of("2014-01-11T-07"), new TimeseriesResultValue(ImmutableMap.of("metric", 3))), new Result<>(queryPlus.getQuery().getIntervals().get(0).getEnd(), new TimeseriesResultValue(ImmutableMap.of("metric", 5)))));
        }
    }, DateTimes.of("2014-08-02T-07").getMillis());
    final Query<Result<TimeseriesResultValue>> query = Druids.newTimeseriesQueryBuilder().dataSource("dummy").intervals("2014-07-31T-07/2014-08-05T-07").granularity(new PeriodGranularity(new Period("P1D"), null, DateTimes.inferTzFromString("America/Phoenix"))).aggregators(Collections.singletonList(new CountAggregatorFactory("count"))).build();
    Assert.assertEquals(Lists.newArrayList(new Result<>(DateTimes.of("2014-07-31T-07"), new TimeseriesResultValue(ImmutableMap.of("metric", 2))), new Result<>(DateTimes.of("2014-08-02T-07"), new TimeseriesResultValue(ImmutableMap.of("metric", 3))), new Result<>(DateTimes.of("2014-08-02T-07"), new TimeseriesResultValue(ImmutableMap.of("metric", 5)))), queryRunner.run(QueryPlus.wrap(query)).toList());
}
Also used : TimeseriesResultValue(org.apache.druid.query.timeseries.TimeseriesResultValue) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) ResponseContext(org.apache.druid.query.context.ResponseContext) PeriodGranularity(org.apache.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) Sequence(org.apache.druid.java.util.common.guava.Sequence) Test(org.junit.Test)

Example 97 with Sequence

use of org.apache.druid.java.util.common.guava.Sequence in project druid by druid-io.

the class DefaultLimitSpecTest method testWithAllGranularity.

@Test
public void testWithAllGranularity() {
    DefaultLimitSpec limitSpec = new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("k1", OrderByColumnSpec.Direction.ASCENDING, StringComparators.NUMERIC)), 2);
    Function<Sequence<ResultRow>, Sequence<ResultRow>> limitFn = limitSpec.build(GroupByQuery.builder().setDataSource("dummy").setInterval("1000/3000").setDimensions(new DefaultDimensionSpec("k1", "k1", ColumnType.DOUBLE)).setGranularity(Granularities.ALL).overrideContext(ImmutableMap.of(GroupByQuery.CTX_KEY_SORT_BY_DIMS_FIRST, true)).build());
    Assert.assertEquals(ImmutableList.of(testRowsList.get(0), testRowsList.get(1)), limitFn.apply(Sequences.simple(testRowsList)).toList());
}
Also used : Sequence(org.apache.druid.java.util.common.guava.Sequence) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 98 with Sequence

use of org.apache.druid.java.util.common.guava.Sequence in project druid by druid-io.

the class BackgroundCachePopulatorTest method before.

@Before
public void before() {
    this.backgroundCachePopulator = new BackgroundCachePopulator(Execs.multiThreaded(2, "CachingQueryRunnerTest-%d"), JSON_MAPPER, new CachePopulatorStats(), -1);
    TopNQueryBuilder builder = new TopNQueryBuilder().dataSource("ds").dimension("top_dim").metric("imps").threshold(3).intervals("2011-01-05/2011-01-10").aggregators(AGGS).granularity(Granularities.ALL);
    this.query = builder.build();
    this.toolchest = new TopNQueryQueryToolChest(new TopNQueryConfig());
    List<Result> expectedRes = makeTopNResults(false, OBJECTS);
    this.closable = new AssertingClosable();
    final Sequence resultSeq = Sequences.wrap(Sequences.simple(expectedRes), new SequenceWrapper() {

        @Override
        public void before() {
            Assert.assertFalse(closable.isClosed());
        }

        @Override
        public void after(boolean isDone, Throwable thrown) {
            closable.close();
        }
    });
    this.baseRunner = (queryPlus, responseContext) -> resultSeq;
    this.cache = new Cache() {

        private final ConcurrentMap<NamedKey, byte[]> baseMap = new ConcurrentHashMap<>();

        @Override
        public byte[] get(NamedKey key) {
            return baseMap.get(key);
        }

        @Override
        public void put(NamedKey key, byte[] value) {
            baseMap.put(key, value);
        }

        @Override
        public Map<NamedKey, byte[]> getBulk(Iterable<NamedKey> keys) {
            return null;
        }

        @Override
        public void close(String namespace) {
        }

        @Override
        public void close() {
        }

        @Override
        public CacheStats getStats() {
            return null;
        }

        @Override
        public boolean isLocal() {
            return true;
        }

        @Override
        public void doMonitor(ServiceEmitter emitter) {
        }
    };
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) SequenceWrapper(org.apache.druid.java.util.common.guava.SequenceWrapper) Sequence(org.apache.druid.java.util.common.guava.Sequence) Result(org.apache.druid.query.Result) TopNQueryConfig(org.apache.druid.query.topn.TopNQueryConfig) TopNQueryQueryToolChest(org.apache.druid.query.topn.TopNQueryQueryToolChest) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Before(org.junit.Before)

Example 99 with Sequence

use of org.apache.druid.java.util.common.guava.Sequence in project druid by druid-io.

the class DirectDruidClientTest method testQueryInterruptionExceptionLogMessage.

@Test
public void testQueryInterruptionExceptionLogMessage() {
    SettableFuture<Object> interruptionFuture = SettableFuture.create();
    Capture<Request> capturedRequest = EasyMock.newCapture();
    final String hostName = "localhost:8080";
    EasyMock.expect(httpClient.go(EasyMock.capture(capturedRequest), EasyMock.<HttpResponseHandler>anyObject(), EasyMock.anyObject(Duration.class))).andReturn(interruptionFuture).anyTimes();
    EasyMock.replay(httpClient);
    // test error
    TimeBoundaryQuery query = Druids.newTimeBoundaryQueryBuilder().dataSource("test").build();
    query = query.withOverriddenContext(ImmutableMap.of(DirectDruidClient.QUERY_FAIL_TIME, Long.MAX_VALUE));
    interruptionFuture.set(new ByteArrayInputStream(StringUtils.toUtf8("{\"error\":\"testing1\",\"errorMessage\":\"testing2\"}")));
    Sequence results = client.run(QueryPlus.wrap(query));
    QueryInterruptedException actualException = null;
    try {
        results.toList();
    } catch (QueryInterruptedException e) {
        actualException = e;
    }
    Assert.assertNotNull(actualException);
    Assert.assertEquals("testing1", actualException.getErrorCode());
    Assert.assertEquals("testing2", actualException.getMessage());
    Assert.assertEquals(hostName, actualException.getHost());
    EasyMock.verify(httpClient);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Request(org.apache.druid.java.util.http.client.Request) TimeBoundaryQuery(org.apache.druid.query.timeboundary.TimeBoundaryQuery) Sequence(org.apache.druid.java.util.common.guava.Sequence) HttpResponseHandler(org.apache.druid.java.util.http.client.response.HttpResponseHandler) QueryInterruptedException(org.apache.druid.query.QueryInterruptedException) Test(org.junit.Test)

Example 100 with Sequence

use of org.apache.druid.java.util.common.guava.Sequence in project druid by druid-io.

the class DirectDruidClientTest method testQueryTimeoutFromFuture.

@Test
public void testQueryTimeoutFromFuture() {
    SettableFuture<Object> noFuture = SettableFuture.create();
    Capture<Request> capturedRequest = EasyMock.newCapture();
    final String queryId = "never-ending-future";
    EasyMock.expect(httpClient.go(EasyMock.capture(capturedRequest), EasyMock.<HttpResponseHandler>anyObject(), EasyMock.anyObject(Duration.class))).andReturn(noFuture).anyTimes();
    EasyMock.replay(httpClient);
    TimeBoundaryQuery query = Druids.newTimeBoundaryQueryBuilder().dataSource("test").build();
    query = query.withOverriddenContext(ImmutableMap.of(DirectDruidClient.QUERY_FAIL_TIME, System.currentTimeMillis() + 500, "queryId", queryId));
    Sequence results = client.run(QueryPlus.wrap(query));
    QueryTimeoutException actualException = null;
    try {
        results.toList();
    } catch (QueryTimeoutException e) {
        actualException = e;
    }
    Assert.assertNotNull(actualException);
    Assert.assertEquals("Query timeout", actualException.getErrorCode());
    Assert.assertEquals(StringUtils.format("Query [%s] timed out!", queryId), actualException.getMessage());
    Assert.assertEquals(hostName, actualException.getHost());
    EasyMock.verify(httpClient);
}
Also used : QueryTimeoutException(org.apache.druid.query.QueryTimeoutException) Request(org.apache.druid.java.util.http.client.Request) TimeBoundaryQuery(org.apache.druid.query.timeboundary.TimeBoundaryQuery) Sequence(org.apache.druid.java.util.common.guava.Sequence) HttpResponseHandler(org.apache.druid.java.util.http.client.response.HttpResponseHandler) Test(org.junit.Test)

Aggregations

Sequence (org.apache.druid.java.util.common.guava.Sequence)102 Test (org.junit.Test)53 List (java.util.List)44 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)37 ResponseContext (org.apache.druid.query.context.ResponseContext)32 ImmutableList (com.google.common.collect.ImmutableList)29 Intervals (org.apache.druid.java.util.common.Intervals)28 Granularities (org.apache.druid.java.util.common.granularity.Granularities)28 QueryRunner (org.apache.druid.query.QueryRunner)28 ArrayList (java.util.ArrayList)27 VirtualColumns (org.apache.druid.segment.VirtualColumns)26 Cursor (org.apache.druid.segment.Cursor)25 QueryPlus (org.apache.druid.query.QueryPlus)24 Result (org.apache.druid.query.Result)24 NullHandling (org.apache.druid.common.config.NullHandling)22 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)22 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)21 QueryableIndexStorageAdapter (org.apache.druid.segment.QueryableIndexStorageAdapter)20 DataSegment (org.apache.druid.timeline.DataSegment)20 ImmutableMap (com.google.common.collect.ImmutableMap)18