Search in sources :

Example 11 with QueryInfo

use of io.trino.execution.QueryInfo in project trino by trinodb.

the class TestQueryResource method getQueryInfo.

private QueryInfo getQueryInfo(String queryId) {
    URI uri = uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/query").appendPath(queryId).addParameter("pretty", "true").build();
    Request request = prepareGet().setUri(uri).setHeader(TRINO_HEADERS.requestUser(), "unknown").build();
    JsonCodec<QueryInfo> codec = server.getInstance(Key.get(JsonCodecFactory.class)).jsonCodec(QueryInfo.class);
    return client.execute(request, createJsonResponseHandler(codec));
}
Also used : Request(io.airlift.http.client.Request) QueryInfo(io.trino.execution.QueryInfo) URI(java.net.URI)

Example 12 with QueryInfo

use of io.trino.execution.QueryInfo in project trino by trinodb.

the class FailedDispatchQuery method immediateFailureQueryInfo.

private static QueryInfo immediateFailureQueryInfo(Session session, String query, Optional<String> preparedQuery, URI self, Optional<ResourceGroupId> resourceGroupId, Throwable throwable) {
    ExecutionFailureInfo failureCause = toFailure(throwable);
    QueryInfo queryInfo = new QueryInfo(session.getQueryId(), session.toSessionRepresentation(), QueryState.FAILED, false, self, ImmutableList.of(), query, preparedQuery, immediateFailureQueryStats(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(), ImmutableSet.of(), ImmutableMap.of(), ImmutableMap.of(), ImmutableSet.of(), Optional.empty(), false, null, Optional.empty(), failureCause, failureCause.getErrorCode(), ImmutableList.of(), ImmutableSet.of(), Optional.empty(), ImmutableList.of(), ImmutableList.of(), true, resourceGroupId, Optional.empty());
    return queryInfo;
}
Also used : BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryInfo(io.trino.execution.QueryInfo) ExecutionFailureInfo(io.trino.execution.ExecutionFailureInfo)

Example 13 with QueryInfo

use of io.trino.execution.QueryInfo in project trino by trinodb.

the class UiQueryResource method getQueryInfo.

@ResourceSecurity(WEB_UI)
@GET
@Path("{queryId}")
public Response getQueryInfo(@PathParam("queryId") QueryId queryId, @Context HttpServletRequest servletRequest, @Context HttpHeaders httpHeaders) {
    requireNonNull(queryId, "queryId is null");
    Optional<QueryInfo> queryInfo = dispatchManager.getFullQueryInfo(queryId);
    if (queryInfo.isPresent()) {
        try {
            checkCanViewQueryOwnedBy(sessionContextFactory.extractAuthorizedIdentity(servletRequest, httpHeaders, alternateHeaderName), queryInfo.get().getSession().toIdentity(), accessControl);
            return Response.ok(queryInfo.get()).build();
        } catch (AccessDeniedException e) {
            throw new ForbiddenException();
        }
    }
    return Response.status(Status.GONE).build();
}
Also used : AccessDeniedException(io.trino.spi.security.AccessDeniedException) ForbiddenException(javax.ws.rs.ForbiddenException) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryInfo(io.trino.execution.QueryInfo) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ResourceSecurity(io.trino.server.security.ResourceSecurity)

Example 14 with QueryInfo

use of io.trino.execution.QueryInfo in project trino by trinodb.

the class Query method create.

public static Query create(Session session, Slug slug, QueryManager queryManager, Optional<URI> queryInfoUrl, DirectExchangeClientSupplier directExchangeClientSupplier, Executor dataProcessorExecutor, ScheduledExecutorService timeoutExecutor, BlockEncodingSerde blockEncodingSerde) {
    DirectExchangeClient exchangeClient = directExchangeClientSupplier.get(session.getQueryId(), new ExchangeId("direct-exchange-query-results"), new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), Query.class.getSimpleName()), queryManager::outputTaskFailed, getRetryPolicy(session));
    Query result = new Query(session, slug, queryManager, queryInfoUrl, exchangeClient, dataProcessorExecutor, timeoutExecutor, blockEncodingSerde);
    result.queryManager.addOutputInfoListener(result.getQueryId(), result::setQueryOutputInfo);
    result.queryManager.addStateChangeListener(result.getQueryId(), state -> {
        if (state.isDone()) {
            QueryInfo queryInfo = queryManager.getFullQueryInfo(result.getQueryId());
            result.closeExchangeClientIfNecessary(queryInfo);
        }
    });
    return result;
}
Also used : SimpleLocalMemoryContext(io.trino.memory.context.SimpleLocalMemoryContext) DirectExchangeClient(io.trino.operator.DirectExchangeClient) QueryInfo(io.trino.execution.QueryInfo) ExchangeId(io.trino.spi.exchange.ExchangeId)

Example 15 with QueryInfo

use of io.trino.execution.QueryInfo in project trino by trinodb.

the class TestQueryManager method testFailQuery.

@Test(timeOut = 60_000L)
public void testFailQuery() throws Exception {
    DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
    QueryId queryId = dispatchManager.createQueryId();
    dispatchManager.createQuery(queryId, Slug.createNew(), TestingSessionContext.fromSession(TEST_SESSION), "SELECT * FROM lineitem").get();
    // wait until query starts running
    while (true) {
        QueryState state = dispatchManager.getQueryInfo(queryId).getState();
        if (state.isDone()) {
            fail("unexpected query state: " + state);
        }
        if (state == RUNNING) {
            break;
        }
        Thread.sleep(100);
    }
    // cancel query
    QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
    queryManager.failQuery(queryId, new TrinoException(GENERIC_INTERNAL_ERROR, "mock exception"));
    QueryInfo queryInfo = queryManager.getFullQueryInfo(queryId);
    assertEquals(queryInfo.getState(), FAILED);
    assertEquals(queryInfo.getErrorCode(), GENERIC_INTERNAL_ERROR.toErrorCode());
    assertNotNull(queryInfo.getFailureInfo());
    assertEquals(queryInfo.getFailureInfo().getMessage(), "mock exception");
}
Also used : DispatchManager(io.trino.dispatcher.DispatchManager) QueryId(io.trino.spi.QueryId) QueryManager(io.trino.execution.QueryManager) TrinoException(io.trino.spi.TrinoException) QueryState(io.trino.execution.QueryState) TestQueryRunnerUtil.waitForQueryState(io.trino.execution.TestQueryRunnerUtil.waitForQueryState) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryInfo(io.trino.execution.QueryInfo) Test(org.testng.annotations.Test)

Aggregations

QueryInfo (io.trino.execution.QueryInfo)16 Test (org.testng.annotations.Test)6 BasicQueryInfo (io.trino.server.BasicQueryInfo)5 QueryManager (io.trino.execution.QueryManager)3 ResourceSecurity (io.trino.server.security.ResourceSecurity)3 QueryId (io.trino.spi.QueryId)3 AccessDeniedException (io.trino.spi.security.AccessDeniedException)3 ForbiddenException (javax.ws.rs.ForbiddenException)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 QueryStats (io.trino.execution.QueryStats)2 BlockBuilder (io.trino.spi.block.BlockBuilder)2 URI (java.net.URI)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 Request (io.airlift.http.client.Request)1 UnexpectedResponseException (io.airlift.http.client.UnexpectedResponseException)1 Duration (io.airlift.units.Duration)1 Session (io.trino.Session)1 QueryResults (io.trino.client.QueryResults)1 DispatchManager (io.trino.dispatcher.DispatchManager)1