Search in sources :

Example 61 with Result

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

the class TimeseriesQueryRunnerBonusTest method testOneRowAtATime.

@Test
public void testOneRowAtATime() throws Exception {
    final IncrementalIndex oneRowIndex = new OnheapIncrementalIndex.Builder().setIndexSchema(new IncrementalIndexSchema.Builder().withMinTimestamp(DateTimes.of("2012-01-01T00:00:00Z").getMillis()).build()).setMaxRowCount(1000).build();
    List<Result<TimeseriesResultValue>> results;
    oneRowIndex.add(new MapBasedInputRow(DateTimes.of("2012-01-01T00:00:00Z").getMillis(), ImmutableList.of("dim1"), ImmutableMap.of("dim1", "x")));
    results = runTimeseriesCount(oneRowIndex);
    Assert.assertEquals("index size", 1, oneRowIndex.size());
    Assert.assertEquals("result size", 1, results.size());
    Assert.assertEquals("result timestamp", DateTimes.of("2012-01-01T00:00:00Z"), results.get(0).getTimestamp());
    Assert.assertEquals("result count metric", 1, (long) results.get(0).getValue().getLongMetric("rows"));
    oneRowIndex.add(new MapBasedInputRow(DateTimes.of("2012-01-01T00:00:00Z").getMillis(), ImmutableList.of("dim1"), ImmutableMap.of("dim1", "y")));
    results = runTimeseriesCount(oneRowIndex);
    Assert.assertEquals("index size", 2, oneRowIndex.size());
    Assert.assertEquals("result size", 1, results.size());
    Assert.assertEquals("result timestamp", DateTimes.of("2012-01-01T00:00:00Z"), results.get(0).getTimestamp());
    Assert.assertEquals("result count metric", 2, (long) results.get(0).getValue().getLongMetric("rows"));
}
Also used : IncrementalIndex(org.apache.druid.segment.incremental.IncrementalIndex) OnheapIncrementalIndex(org.apache.druid.segment.incremental.OnheapIncrementalIndex) OnheapIncrementalIndex(org.apache.druid.segment.incremental.OnheapIncrementalIndex) MapBasedInputRow(org.apache.druid.data.input.MapBasedInputRow) IncrementalIndexSchema(org.apache.druid.segment.incremental.IncrementalIndexSchema) Result(org.apache.druid.query.Result) Test(org.junit.Test)

Example 62 with Result

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

the class TimeseriesQueryEngine method process.

/**
 * Run a single-segment, single-interval timeseries query on a particular adapter. The query must have been
 * scoped down to a single interval before calling this method.
 */
public Sequence<Result<TimeseriesResultValue>> process(final TimeseriesQuery query, final StorageAdapter adapter) {
    if (adapter == null) {
        throw new SegmentMissingException("Null storage adapter found. Probably trying to issue a query against a segment being memory unmapped.");
    }
    final Filter filter = Filters.convertToCNFFromQueryContext(query, Filters.toFilter(query.getFilter()));
    final Interval interval = Iterables.getOnlyElement(query.getIntervals());
    final Granularity gran = query.getGranularity();
    final boolean descending = query.isDescending();
    final ColumnInspector inspector = query.getVirtualColumns().wrapInspector(adapter);
    final boolean doVectorize = QueryContexts.getVectorize(query).shouldVectorize(adapter.canVectorize(filter, query.getVirtualColumns(), descending) && VirtualColumns.shouldVectorize(query, query.getVirtualColumns(), adapter) && query.getAggregatorSpecs().stream().allMatch(aggregatorFactory -> aggregatorFactory.canVectorize(inspector)));
    final Sequence<Result<TimeseriesResultValue>> result;
    if (doVectorize) {
        result = processVectorized(query, adapter, filter, interval, gran, descending);
    } else {
        result = processNonVectorized(query, adapter, filter, interval, gran, descending);
    }
    final int limit = query.getLimit();
    if (limit < Integer.MAX_VALUE) {
        return result.limit(limit);
    } else {
        return result;
    }
}
Also used : Filter(org.apache.druid.query.filter.Filter) SegmentMissingException(org.apache.druid.segment.SegmentMissingException) ColumnInspector(org.apache.druid.segment.ColumnInspector) Granularity(org.apache.druid.java.util.common.granularity.Granularity) Interval(org.joda.time.Interval) Result(org.apache.druid.query.Result)

Example 63 with Result

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

the class TimeBoundaryQueryRunnerTest method testTimeBoundaryMax.

@Test
@SuppressWarnings("unchecked")
public void testTimeBoundaryMax() {
    TimeBoundaryQuery timeBoundaryQuery = Druids.newTimeBoundaryQueryBuilder().dataSource("testing").bound(TimeBoundaryQuery.MAX_TIME).build();
    ResponseContext context = ConcurrentResponseContext.createEmpty();
    context.initializeMissingSegments();
    Iterable<Result<TimeBoundaryResultValue>> results = runner.run(QueryPlus.wrap(timeBoundaryQuery), context).toList();
    TimeBoundaryResultValue val = results.iterator().next().getValue();
    DateTime minTime = val.getMinTime();
    DateTime maxTime = val.getMaxTime();
    Assert.assertNull(minTime);
    Assert.assertEquals(DateTimes.of("2011-04-15T00:00:00.000Z"), maxTime);
}
Also used : ResponseContext(org.apache.druid.query.context.ResponseContext) ConcurrentResponseContext(org.apache.druid.query.context.ConcurrentResponseContext) DateTime(org.joda.time.DateTime) Result(org.apache.druid.query.Result) Test(org.junit.Test)

Example 64 with Result

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

the class TimeBoundaryQueryRunnerTest method testMergeResults.

@Test
public void testMergeResults() {
    List<Result<TimeBoundaryResultValue>> results = Arrays.asList(new Result<>(DateTimes.nowUtc(), new TimeBoundaryResultValue(ImmutableMap.of("maxTime", "2012-01-01", "minTime", "2011-01-01"))), new Result<>(DateTimes.nowUtc(), new TimeBoundaryResultValue(ImmutableMap.of("maxTime", "2012-02-01", "minTime", "2011-01-01"))));
    TimeBoundaryQuery query = new TimeBoundaryQuery(new TableDataSource("test"), null, null, null, null);
    Iterable<Result<TimeBoundaryResultValue>> actual = query.mergeResults(results);
    Assert.assertTrue(actual.iterator().next().getValue().getMaxTime().equals(DateTimes.of("2012-02-01")));
}
Also used : TableDataSource(org.apache.druid.query.TableDataSource) Result(org.apache.druid.query.Result) Test(org.junit.Test)

Example 65 with Result

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

the class TimeBoundaryQueryRunnerTest method testMergeResultsEmptyResults.

@Test
public void testMergeResultsEmptyResults() {
    List<Result<TimeBoundaryResultValue>> results = new ArrayList<>();
    TimeBoundaryQuery query = new TimeBoundaryQuery(new TableDataSource("test"), null, null, null, null);
    Iterable<Result<TimeBoundaryResultValue>> actual = query.mergeResults(results);
    Assert.assertFalse(actual.iterator().hasNext());
}
Also used : TableDataSource(org.apache.druid.query.TableDataSource) ArrayList(java.util.ArrayList) Result(org.apache.druid.query.Result) 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