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;
}
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());
}
}
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);
}
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);
}
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);
}
Aggregations