use of io.trino.execution.QueryState in project trino by trinodb.
the class UiQueryResource method getAllQueryInfo.
@ResourceSecurity(WEB_UI)
@GET
public List<TrimmedBasicQueryInfo> getAllQueryInfo(@QueryParam("state") String stateFilter, @Context HttpServletRequest servletRequest, @Context HttpHeaders httpHeaders) {
QueryState expectedState = stateFilter == null ? null : QueryState.valueOf(stateFilter.toUpperCase(Locale.ENGLISH));
List<BasicQueryInfo> queries = dispatchManager.getQueries();
queries = filterQueries(sessionContextFactory.extractAuthorizedIdentity(servletRequest, httpHeaders, alternateHeaderName), queries, accessControl);
ImmutableList.Builder<TrimmedBasicQueryInfo> builder = ImmutableList.builder();
for (BasicQueryInfo queryInfo : queries) {
if (stateFilter == null || queryInfo.getState() == expectedState) {
builder.add(new TrimmedBasicQueryInfo(queryInfo));
}
}
return builder.build();
}
use of io.trino.execution.QueryState in project trino by trinodb.
the class TestTrinoDriver method testUpdateCancelExplicit.
@Test(timeOut = 10000)
public void testUpdateCancelExplicit() throws Exception {
CountDownLatch queryFinished = new CountDownLatch(1);
AtomicReference<Throwable> queryFailure = new AtomicReference<>();
String queryUuid = "/* " + UUID.randomUUID().toString() + " */";
try (Connection connection = createConnection("blackhole", "blackhole");
Statement statement = connection.createStatement()) {
// execute the slow update on another thread
executorService.execute(() -> {
try {
statement.executeUpdate("CREATE TABLE test_cancel_create AS SELECT * FROM slow_test_table " + queryUuid);
} catch (SQLException t) {
queryFailure.set(t);
} finally {
queryFinished.countDown();
}
});
// start query and make sure it is not finished
while (true) {
Optional<QueryState> state = findQueryState(queryUuid);
if (state.isPresent()) {
assertFalse(state.get().isDone());
break;
}
MILLISECONDS.sleep(50);
}
// cancel the query from this test thread
statement.cancel();
// make sure the query was aborted
queryFinished.await(10, SECONDS);
assertNotNull(queryFailure.get());
assertEquals(findQueryState(queryUuid), Optional.of(FAILED));
}
}
use of io.trino.execution.QueryState in project trino by trinodb.
the class QueryResource method getAllQueryInfo.
@ResourceSecurity(AUTHENTICATED_USER)
@GET
public List<BasicQueryInfo> getAllQueryInfo(@QueryParam("state") String stateFilter, @Context HttpServletRequest servletRequest, @Context HttpHeaders httpHeaders) {
QueryState expectedState = stateFilter == null ? null : QueryState.valueOf(stateFilter.toUpperCase(Locale.ENGLISH));
List<BasicQueryInfo> queries = dispatchManager.getQueries();
queries = filterQueries(sessionContextFactory.extractAuthorizedIdentity(servletRequest, httpHeaders, alternateHeaderName), queries, accessControl);
ImmutableList.Builder<BasicQueryInfo> builder = ImmutableList.builder();
for (BasicQueryInfo queryInfo : queries) {
if (stateFilter == null || queryInfo.getState() == expectedState) {
builder.add(queryInfo);
}
}
return builder.build();
}
use of io.trino.execution.QueryState in project trino by trinodb.
the class TestTrinoDriver method findQueryState.
private Optional<QueryState> findQueryState(String text) throws SQLException {
String sql = format("SELECT state FROM system.runtime.queries WHERE regexp_like(query, '%s$') /* */", Pattern.quote(text));
try (Connection connection = createConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(sql)) {
if (!resultSet.next()) {
return Optional.empty();
}
QueryState state = QueryState.valueOf(requireNonNull(resultSet.getString(1)));
assertFalse(resultSet.next(), "Found multiple queries");
return Optional.of(state);
}
}
use of io.trino.execution.QueryState in project trino by trinodb.
the class Query method toQueryError.
private static QueryError toQueryError(QueryInfo queryInfo, Optional<Throwable> exception) {
QueryState state = queryInfo.getState();
if (state != FAILED && exception.isEmpty()) {
return null;
}
ExecutionFailureInfo executionFailure;
if (queryInfo.getFailureInfo() != null) {
executionFailure = queryInfo.getFailureInfo();
} else if (exception.isPresent()) {
executionFailure = toFailure(exception.get());
} else {
log.warn("Query %s in state %s has no failure info", queryInfo.getQueryId(), state);
executionFailure = toFailure(new RuntimeException(format("Query is %s (reason unknown)", state)));
}
FailureInfo failure = executionFailure.toFailureInfo();
ErrorCode errorCode;
if (queryInfo.getErrorCode() != null) {
errorCode = queryInfo.getErrorCode();
} else if (exception.isPresent()) {
errorCode = SERIALIZATION_ERROR.toErrorCode();
} else {
errorCode = GENERIC_INTERNAL_ERROR.toErrorCode();
log.warn("Failed query %s has no error code", queryInfo.getQueryId());
}
return new QueryError(firstNonNull(failure.getMessage(), "Internal error"), null, errorCode.getCode(), errorCode.getName(), errorCode.getType().toString(), failure.getErrorLocation(), failure);
}
Aggregations