Search in sources :

Example 6 with TimeBoundaryQuery

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

the class CachingClusteredClientTest method testIfNoneMatch.

@Test
public void testIfNoneMatch() {
    Interval interval = Intervals.of("2016/2017");
    final DataSegment dataSegment = new DataSegment("dataSource", interval, "ver", ImmutableMap.of("type", "hdfs", "path", "/tmp"), ImmutableList.of("product"), ImmutableList.of("visited_sum"), NoneShardSpec.instance(), 9, 12334);
    final ServerSelector selector = new ServerSelector(dataSegment, new HighestPriorityTierSelectorStrategy(new RandomServerSelectorStrategy()));
    selector.addServerAndUpdateSegment(new QueryableDruidServer(servers[0], null), dataSegment);
    timeline.add(interval, "ver", new SingleElementPartitionChunk<>(selector));
    TimeBoundaryQuery query = Druids.newTimeBoundaryQueryBuilder().dataSource(DATA_SOURCE).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(interval))).context(ImmutableMap.of("If-None-Match", "aVJV29CJY93rszVW/QBy0arWZo0=")).randomQueryId().build();
    final ResponseContext responseContext = initializeResponseContext();
    getDefaultQueryRunner().run(QueryPlus.wrap(query), responseContext);
    Assert.assertEquals("MDs2yIUvYLVzaG6zmwTH1plqaYE=", responseContext.getEntityTag());
}
Also used : ServerSelector(org.apache.druid.client.selector.ServerSelector) HighestPriorityTierSelectorStrategy(org.apache.druid.client.selector.HighestPriorityTierSelectorStrategy) ResponseContext(org.apache.druid.query.context.ResponseContext) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) TimeBoundaryQuery(org.apache.druid.query.timeboundary.TimeBoundaryQuery) DataSegment(org.apache.druid.timeline.DataSegment) RandomServerSelectorStrategy(org.apache.druid.client.selector.RandomServerSelectorStrategy) Interval(org.joda.time.Interval) QueryableDruidServer(org.apache.druid.client.selector.QueryableDruidServer) Test(org.junit.Test)

Example 7 with TimeBoundaryQuery

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

the class SchemalessTestSimpleTest method testTimeBoundary.

@Test
public void testTimeBoundary() {
    TimeBoundaryQuery query = Druids.newTimeBoundaryQueryBuilder().dataSource("testing").build();
    List<Result<TimeBoundaryResultValue>> expectedResults = Collections.singletonList(new Result<TimeBoundaryResultValue>(DateTimes.of("2011-01-12T00:00:00.000Z"), new TimeBoundaryResultValue(ImmutableMap.of(TimeBoundaryQuery.MIN_TIME, DateTimes.of("2011-01-12T00:00:00.000Z"), TimeBoundaryQuery.MAX_TIME, DateTimes.of("2011-01-13T00:00:00.000Z")))));
    QueryRunner runner = TestQueryRunners.makeTimeBoundaryQueryRunner(segment);
    TestHelper.assertExpectedResults(expectedResults, runner.run(QueryPlus.wrap(query)));
}
Also used : TimeBoundaryResultValue(org.apache.druid.query.timeboundary.TimeBoundaryResultValue) TimeBoundaryQuery(org.apache.druid.query.timeboundary.TimeBoundaryQuery) QueryRunner(org.apache.druid.query.QueryRunner) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 8 with TimeBoundaryQuery

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

the class SchemalessTestFullTest method testTimeBoundary.

private void testTimeBoundary(QueryRunner runner, List<Result<TimeBoundaryResultValue>> expectedResults, String failMsg) {
    TimeBoundaryQuery query = Druids.newTimeBoundaryQueryBuilder().dataSource("testing").build();
    failMsg += " timeBoundary ";
    Iterable<Result<TimeBoundaryResultValue>> actualResults = runner.run(QueryPlus.wrap(query)).toList();
    TestHelper.assertExpectedResults(expectedResults, actualResults, failMsg);
}
Also used : TimeBoundaryQuery(org.apache.druid.query.timeboundary.TimeBoundaryQuery) Result(org.apache.druid.query.Result)

Example 9 with TimeBoundaryQuery

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

the class QueryHostFinderTest method testFindServer.

@Test
public void testFindServer() {
    QueryHostFinder queryRunner = new QueryHostFinder(brokerSelector, new RendezvousHashAvaticaConnectionBalancer());
    Server server = queryRunner.findServer(new TimeBoundaryQuery(new TableDataSource("test"), new MultipleIntervalSegmentSpec(Collections.singletonList(Intervals.of("2011-08-31/2011-09-01"))), null, null, null));
    Assert.assertEquals("foo", server.getHost());
}
Also used : Server(org.apache.druid.client.selector.Server) TableDataSource(org.apache.druid.query.TableDataSource) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) TimeBoundaryQuery(org.apache.druid.query.timeboundary.TimeBoundaryQuery) Test(org.junit.Test)

Example 10 with TimeBoundaryQuery

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

the class TimewarpOperator method postProcess.

public QueryRunner<T> postProcess(final QueryRunner<T> baseRunner, final long now) {
    return new QueryRunner<T>() {

        @Override
        public Sequence<T> run(final QueryPlus<T> queryPlus, final ResponseContext responseContext) {
            final DateTimeZone tz = queryPlus.getQuery().getTimezone();
            final long offset = computeOffset(now, tz);
            final Interval interval = queryPlus.getQuery().getIntervals().get(0);
            final Interval modifiedInterval = new Interval(Math.min(interval.getStartMillis() + offset, now + offset), Math.min(interval.getEndMillis() + offset, now + offset), interval.getChronology());
            return Sequences.map(baseRunner.run(queryPlus.withQuery(queryPlus.getQuery().withQuerySegmentSpec(new MultipleIntervalSegmentSpec(Collections.singletonList(modifiedInterval)))), responseContext), new Function<T, T>() {

                @Override
                public T apply(T input) {
                    if (input instanceof Result) {
                        Result res = (Result) input;
                        Object value = res.getValue();
                        if (value instanceof TimeBoundaryResultValue) {
                            TimeBoundaryResultValue boundary = (TimeBoundaryResultValue) value;
                            DateTime minTime;
                            try {
                                minTime = boundary.getMinTime();
                            } catch (IllegalArgumentException e) {
                                minTime = null;
                            }
                            final DateTime maxTime = boundary.getMaxTime();
                            return (T) ((TimeBoundaryQuery) queryPlus.getQuery()).buildResult(DateTimes.utc(Math.min(res.getTimestamp().getMillis() - offset, now)), minTime != null ? minTime.minus(offset) : null, maxTime != null ? DateTimes.utc(Math.min(maxTime.getMillis() - offset, now)) : null).iterator().next();
                        }
                        return (T) new Result(res.getTimestamp().minus(offset), value);
                    } else if (input instanceof MapBasedRow) {
                        MapBasedRow row = (MapBasedRow) input;
                        return (T) new MapBasedRow(row.getTimestamp().minus(offset), row.getEvent());
                    }
                    // default to noop for unknown result types
                    return input;
                }
            });
        }
    };
}
Also used : MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) TimeBoundaryQuery(org.apache.druid.query.timeboundary.TimeBoundaryQuery) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) MapBasedRow(org.apache.druid.data.input.MapBasedRow) ResponseContext(org.apache.druid.query.context.ResponseContext) TimeBoundaryResultValue(org.apache.druid.query.timeboundary.TimeBoundaryResultValue) Interval(org.joda.time.Interval)

Aggregations

TimeBoundaryQuery (org.apache.druid.query.timeboundary.TimeBoundaryQuery)12 Test (org.junit.Test)9 Sequence (org.apache.druid.java.util.common.guava.Sequence)5 Request (org.apache.druid.java.util.http.client.Request)5 HttpResponseHandler (org.apache.druid.java.util.http.client.response.HttpResponseHandler)5 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)5 QueryableDruidServer (org.apache.druid.client.selector.QueryableDruidServer)4 Result (org.apache.druid.query.Result)4 Interval (org.joda.time.Interval)4 ResponseContext (org.apache.druid.query.context.ResponseContext)3 TimeBoundaryResultValue (org.apache.druid.query.timeboundary.TimeBoundaryResultValue)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 PipedInputStream (java.io.PipedInputStream)2 HighestPriorityTierSelectorStrategy (org.apache.druid.client.selector.HighestPriorityTierSelectorStrategy)2 RandomServerSelectorStrategy (org.apache.druid.client.selector.RandomServerSelectorStrategy)2 ServerSelector (org.apache.druid.client.selector.ServerSelector)2 QueryRunner (org.apache.druid.query.QueryRunner)2 DataSegment (org.apache.druid.timeline.DataSegment)2 Function (com.google.common.base.Function)1 ImmutableList (com.google.common.collect.ImmutableList)1