Search in sources :

Example 6 with ResponseContext

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

the class QueryRunnerBasedOnClusteredClientTestBase method responseContext.

protected static ResponseContext responseContext() {
    final ResponseContext responseContext = ConcurrentResponseContext.createEmpty();
    responseContext.initializeRemainingResponses();
    return responseContext;
}
Also used : ResponseContext(org.apache.druid.query.context.ResponseContext) ConcurrentResponseContext(org.apache.druid.query.context.ConcurrentResponseContext)

Example 7 with ResponseContext

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

the class ScanQueryRunnerTest method testScanQueryTimeout.

@Test
public void testScanQueryTimeout() {
    ScanQuery query = newTestQuery().intervals(I_0112_0114).virtualColumns(EXPR_COLUMN).context(ImmutableMap.of(QueryContexts.TIMEOUT_KEY, 1)).build();
    ResponseContext responseContext = DefaultResponseContext.createEmpty();
    responseContext.putTimeoutTime(System.currentTimeMillis());
    try {
        runner.run(QueryPlus.wrap(query), responseContext).toList();
        Assert.fail("didn't timeout");
    } catch (RuntimeException e) {
        Assert.assertTrue(e instanceof QueryTimeoutException);
        Assert.assertEquals("Query timeout", ((QueryTimeoutException) e).getErrorCode());
    }
}
Also used : QueryTimeoutException(org.apache.druid.query.QueryTimeoutException) DefaultResponseContext(org.apache.druid.query.context.DefaultResponseContext) ResponseContext(org.apache.druid.query.context.ResponseContext) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 8 with ResponseContext

use of org.apache.druid.query.context.ResponseContext 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 9 with ResponseContext

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

the class QueryLifecycle method execute.

/**
 * Execute the query. Can only be called if the query has been authorized. Note that query logs and metrics will
 * not be emitted automatically when the Sequence is fully iterated. It is the caller's responsibility to call
 * {@link #emitLogsAndMetrics(Throwable, String, long)} to emit logs and metrics.
 *
 * @return result sequence and response context
 */
public QueryResponse execute() {
    transition(State.AUTHORIZED, State.EXECUTING);
    final ResponseContext responseContext = DirectDruidClient.makeResponseContextForQuery();
    final Sequence res = QueryPlus.wrap(baseQuery).withIdentity(authenticationResult.getIdentity()).run(texasRanger, responseContext);
    return new QueryResponse(res == null ? Sequences.empty() : res, responseContext);
}
Also used : ResponseContext(org.apache.druid.query.context.ResponseContext) Sequence(org.apache.druid.java.util.common.guava.Sequence)

Example 10 with ResponseContext

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

the class NestedQueryPushDownTest method runNestedQueryWithForcePushDown.

private Sequence<ResultRow> runNestedQueryWithForcePushDown(GroupByQuery nestedQuery) {
    ResponseContext context = ResponseContext.createEmpty();
    QueryToolChest<ResultRow, GroupByQuery> toolChest = groupByFactory.getToolchest();
    GroupByQuery pushDownQuery = nestedQuery;
    QueryRunner<ResultRow> segment1Runner = new FinalizeResultsQueryRunner<ResultRow>(toolChest.mergeResults(groupByFactory.mergeRunners(executorService, getQueryRunnerForSegment1())), (QueryToolChest) toolChest);
    QueryRunner<ResultRow> segment2Runner = new FinalizeResultsQueryRunner<ResultRow>(toolChest.mergeResults(groupByFactory2.mergeRunners(executorService, getQueryRunnerForSegment2())), (QueryToolChest) toolChest);
    QueryRunner<ResultRow> queryRunnerForSegments = new FinalizeResultsQueryRunner<>(toolChest.mergeResults((queryPlus, responseContext) -> Sequences.simple(ImmutableList.of(Sequences.map(segment1Runner.run(queryPlus, responseContext), toolChest.makePreComputeManipulatorFn((GroupByQuery) queryPlus.getQuery(), MetricManipulatorFns.deserializing())), Sequences.map(segment2Runner.run(queryPlus, responseContext), toolChest.makePreComputeManipulatorFn((GroupByQuery) queryPlus.getQuery(), MetricManipulatorFns.deserializing())))).flatMerge(Function.identity(), queryPlus.getQuery().getResultOrdering())), (QueryToolChest) toolChest);
    GroupByStrategy strategy = ((GroupByQueryRunnerFactory) groupByFactory).getStrategySelector().strategize(nestedQuery);
    // Historicals execute the query with force push down flag as false
    GroupByQuery queryWithPushDownDisabled = pushDownQuery.withOverriddenContext(ImmutableMap.of(GroupByQueryConfig.CTX_KEY_FORCE_PUSH_DOWN_NESTED_QUERY, false));
    Sequence<ResultRow> pushDownQueryResults = strategy.mergeResults(queryRunnerForSegments, queryWithPushDownDisabled, context);
    return toolChest.mergeResults((queryPlus, responseContext) -> pushDownQueryResults).run(QueryPlus.wrap(nestedQuery), context);
}
Also used : QueryPlus(org.apache.druid.query.QueryPlus) Arrays(java.util.Arrays) LongDimensionSchema(org.apache.druid.data.input.impl.LongDimensionSchema) StupidPool(org.apache.druid.collections.StupidPool) IndexSpec(org.apache.druid.segment.IndexSpec) DefaultBlockingPool(org.apache.druid.collections.DefaultBlockingPool) ByteBuffer(java.nio.ByteBuffer) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) QueryWatcher(org.apache.druid.query.QueryWatcher) After(org.junit.After) Map(java.util.Map) QueryRunner(org.apache.druid.query.QueryRunner) GroupByStrategySelector(org.apache.druid.query.groupby.strategy.GroupByStrategySelector) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) FileUtils(org.apache.druid.java.util.common.FileUtils) OffHeapMemorySegmentWriteOutMediumFactory(org.apache.druid.segment.writeout.OffHeapMemorySegmentWriteOutMediumFactory) GroupByStrategy(org.apache.druid.query.groupby.strategy.GroupByStrategy) Sequence(org.apache.druid.java.util.common.guava.Sequence) FinalizeResultsQueryRunner(org.apache.druid.query.FinalizeResultsQueryRunner) Execs(org.apache.druid.java.util.common.concurrent.Execs) ImmutableMap(com.google.common.collect.ImmutableMap) QueryableIndex(org.apache.druid.segment.QueryableIndex) DruidProcessingConfig(org.apache.druid.query.DruidProcessingConfig) RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) StringDimensionSchema(org.apache.druid.data.input.impl.StringDimensionSchema) BySegmentQueryRunner(org.apache.druid.query.BySegmentQueryRunner) QuerySegmentSpec(org.apache.druid.query.spec.QuerySegmentSpec) IncrementalIndexSchema(org.apache.druid.segment.incremental.IncrementalIndexSchema) ExprMacroTable(org.apache.druid.math.expr.ExprMacroTable) InputRow(org.apache.druid.data.input.InputRow) BlockingPool(org.apache.druid.collections.BlockingPool) List(java.util.List) SegmentId(org.apache.druid.timeline.SegmentId) QueryableIndexSegment(org.apache.druid.segment.QueryableIndexSegment) Logger(org.apache.druid.java.util.common.logger.Logger) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) NonBlockingPool(org.apache.druid.collections.NonBlockingPool) Intervals(org.apache.druid.java.util.common.Intervals) Supplier(com.google.common.base.Supplier) MetricManipulatorFns(org.apache.druid.query.aggregation.MetricManipulatorFns) MapBasedInputRow(org.apache.druid.data.input.MapBasedInputRow) HashMap(java.util.HashMap) Function(java.util.function.Function) JavaScriptConfig(org.apache.druid.js.JavaScriptConfig) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Query(org.apache.druid.query.Query) IncrementalIndex(org.apache.druid.segment.incremental.IncrementalIndex) Suppliers(com.google.common.base.Suppliers) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) IndexMergerV9(org.apache.druid.segment.IndexMergerV9) OnheapIncrementalIndex(org.apache.druid.segment.incremental.OnheapIncrementalIndex) Sequences(org.apache.druid.java.util.common.guava.Sequences) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) Segment(org.apache.druid.segment.Segment) GroupByStrategyV2(org.apache.druid.query.groupby.strategy.GroupByStrategyV2) ResponseContext(org.apache.druid.query.context.ResponseContext) GroupByStrategyV1(org.apache.druid.query.groupby.strategy.GroupByStrategyV1) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) QueryToolChest(org.apache.druid.query.QueryToolChest) DimensionsSpec(org.apache.druid.data.input.impl.DimensionsSpec) Test(org.junit.Test) GreaterThanHavingSpec(org.apache.druid.query.groupby.having.GreaterThanHavingSpec) SmileFactory(com.fasterxml.jackson.dataformat.smile.SmileFactory) File(java.io.File) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Granularities(org.apache.druid.java.util.common.granularity.Granularities) LongMaxAggregatorFactory(org.apache.druid.query.aggregation.LongMaxAggregatorFactory) AtomicLong(java.util.concurrent.atomic.AtomicLong) QueryRunnerFactory(org.apache.druid.query.QueryRunnerFactory) Assert(org.junit.Assert) IndexIO(org.apache.druid.segment.IndexIO) Collections(java.util.Collections) JavaScriptDimFilter(org.apache.druid.query.filter.JavaScriptDimFilter) FinalizeResultsQueryRunner(org.apache.druid.query.FinalizeResultsQueryRunner) ResponseContext(org.apache.druid.query.context.ResponseContext) GroupByStrategy(org.apache.druid.query.groupby.strategy.GroupByStrategy)

Aggregations

ResponseContext (org.apache.druid.query.context.ResponseContext)65 Test (org.junit.Test)44 QueryRunner (org.apache.druid.query.QueryRunner)39 QueryPlus (org.apache.druid.query.QueryPlus)35 Sequence (org.apache.druid.java.util.common.guava.Sequence)30 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)26 FinalizeResultsQueryRunner (org.apache.druid.query.FinalizeResultsQueryRunner)23 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)22 Interval (org.joda.time.Interval)19 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)16 ArrayList (java.util.ArrayList)14 MergeSequence (org.apache.druid.java.util.common.guava.MergeSequence)14 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)14 Result (org.apache.druid.query.Result)12 DefaultLimitSpec (org.apache.druid.query.groupby.orderby.DefaultLimitSpec)12 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)11 List (java.util.List)10 ChainedExecutionQueryRunner (org.apache.druid.query.ChainedExecutionQueryRunner)10 SegmentDescriptor (org.apache.druid.query.SegmentDescriptor)10 OrderByColumnSpec (org.apache.druid.query.groupby.orderby.OrderByColumnSpec)10