@Override
public GetQueryResultResponse getQueryResult(RpcController controller,
GetQueryResultRequest request) throws ServiceException {
try {
context.getSessionManager().touch(request.getSessionId().getId());
QueryId queryId = new QueryId(request.getQueryId());
QueryInProgress queryInProgress = context.getQueryJobManager().getQueryInProgress(queryId);
// if we cannot get a QueryInProgress instance from QueryJobManager,
// the instance can be in the finished query list.
if (queryInProgress == null) {
queryInProgress = context.getQueryJobManager().getFinishedQuery(queryId);
}
GetQueryResultResponse.Builder builder = GetQueryResultResponse.newBuilder();
// If we cannot the QueryInProgress instance from the finished list,
// the query result was expired due to timeout.
// In this case, we will result in error.
if (queryInProgress == null) {
builder.setErrorMessage("No such query: " + queryId.toString());
return builder.build();
}
QueryInfo queryInfo = queryInProgress.getQueryInfo();