Source:
<code>public GetQueryStatusResponse getQueryStatus(RpcController controller, GetQueryStatusRequest request) throws ServiceException { GetQueryStatusResponse.Builder builder = GetQueryStatusResponse.newBuilder(); try { context.getSessionManager().touch(request.getSessionId().getId()); QueryId queryId = new QueryId(request.getQueryId()); builder.setQueryId(request.getQueryId()); if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) { builder.setState(OK); builder.setQueryState(QueryState.QUERY_SUCCEEDED); } else { QueryInProgress queryInProgress = context.getQueryJobManager().getQueryInProgress(queryId); QueryInfo queryInfo = null; if (queryInProgress == null) { queryInfo = context.getQueryJobManager().getFinishedQuery(queryId); } else { queryInfo = queryInProgress.getQueryInfo(); } if (queryInfo != null) { builder.setState(OK); builder.setQueryState(queryInfo.getQueryState()); boolean isCreateTable = queryInfo.getQueryContext().isCreateTable(); boolean isInsert = queryInfo.getQueryContext().isInsert(); builder.setHasResult(!(isCreateTable || isInsert)); builder.setProgress(queryInfo.getProgress()); builder.setSubmitTime(queryInfo.getStartTime()); if(queryInfo.getQueryMasterHost() != null) { builder.setQueryMasterHost(queryInfo.getQueryMasterHost()); builder.setQueryMasterPort(queryInfo.getQueryMasterClientPort()); } if (queryInfo.getQueryState() == QueryState.QUERY_SUCCEEDED) { builder.setFinishTime(queryInfo.getFinishTime()); } else { builder.setFinishTime(System.currentTimeMillis()); if(!StringUtils.isEmpty(queryInfo.getLastMessage())) { builder.setErrorMessage(queryInfo.getLastMessage()); } <START> builder.setState(OK); <END> } } else { Session session = context.getSessionManager().getSession(request.getSessionId().getId()); if (session.getNonForwardQueryResultScanner(queryId) != null) { builder.setState(OK); builder.setQueryState(QueryState.QUERY_SUCCEEDED); } else { builder.setState(errNoSuchQueryId(queryId)); } } } } catch (Throwable t) { printStackTraceIfError(LOG, t); builder.setState(returnError(t)); } return builder.build(); }</code><technical_language>duplicate code set query state</technical_language>

Target:
public GetQueryStatusResponse getQueryStatus(RpcController controller, GetQueryStatusRequest request) throws ServiceException { GetQueryStatusResponse.Builder builder = GetQueryStatusResponse.newBuilder(); try { context.getSessionManager().touch(request.getSessionId().getId()); QueryId queryId = new QueryId(request.getQueryId()); builder.setQueryId(request.getQueryId()); if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) { builder.setState(OK); builder.setQueryState(QueryState.QUERY_SUCCEEDED); } else { QueryInProgress queryInProgress = context.getQueryJobManager().getQueryInProgress(queryId); QueryInfo queryInfo = null; if (queryInProgress == null) { queryInfo = context.getQueryJobManager().getFinishedQuery(queryId); } else { queryInfo = queryInProgress.getQueryInfo(); } if (queryInfo != null) { builder.setState(OK); builder.setQueryState(queryInfo.getQueryState()); boolean isCreateTable = queryInfo.getQueryContext().isCreateTable(); boolean isInsert = queryInfo.getQueryContext().isInsert(); builder.setHasResult(!(isCreateTable || isInsert)); builder.setProgress(queryInfo.getProgress()); builder.setSubmitTime(queryInfo.getStartTime()); if(queryInfo.getQueryMasterHost() != null) { builder.setQueryMasterHost(queryInfo.getQueryMasterHost()); builder.setQueryMasterPort(queryInfo.getQueryMasterClientPort()); } if (queryInfo.getQueryState() == QueryState.QUERY_SUCCEEDED) { builder.setFinishTime(queryInfo.getFinishTime()); } else { builder.setFinishTime(System.currentTimeMillis()); if(!StringUtils.isEmpty(queryInfo.getLastMessage())) { builder.setErrorMessage(queryInfo.getLastMessage()); } } } else { Session session = context.getSessionManager().getSession(request.getSessionId().getId()); if (session.getNonForwardQueryResultScanner(queryId) != null) { builder.setState(OK); builder.setQueryState(QueryState.QUERY_SUCCEEDED); } else { builder.setState(errNoSuchQueryId(queryId)); } } } } catch (Throwable t) { printStackTraceIfError(LOG, t); builder.setState(returnError(t)); } return builder.build(); }