Search in sources :

Example 1 with QueryResult

use of org.apache.drill.exec.proto.UserBitShared.QueryResult in project drill by apache.

the class QueryResultHandler method resultArrived.

/**
   * Maps internal low-level API protocol to {@link UserResultsListener}-level API protocol.
   * handles data result messages
   */
public void resultArrived(ByteBuf pBody) throws RpcException {
    final QueryResult queryResult = RpcBus.get(pBody, QueryResult.PARSER);
    final QueryId queryId = queryResult.getQueryId();
    final QueryState queryState = queryResult.getQueryState();
    if (logger.isDebugEnabled()) {
        logger.debug("resultArrived: queryState: {}, queryId = {}", queryState, QueryIdHelper.getQueryId(queryId));
    }
    assert queryResult.hasQueryState() : "received query result without QueryState";
    final boolean isFailureResult = QueryState.FAILED == queryState;
    // CANCELED queries are handled the same way as COMPLETED
    final boolean isTerminalResult;
    switch(queryState) {
        case FAILED:
        case CANCELED:
        case COMPLETED:
            isTerminalResult = true;
            break;
        default:
            logger.error("Unexpected/unhandled QueryState " + queryState + " (for query " + queryId + ")");
            isTerminalResult = false;
            break;
    }
    assert isFailureResult || queryResult.getErrorCount() == 0 : "Error count for the query batch is non-zero but QueryState != FAILED";
    UserResultsListener resultsListener = newUserResultsListener(queryId);
    try {
        if (isFailureResult) {
            // Failure case--pass on via submissionFailed(...).
            resultsListener.submissionFailed(new UserRemoteException(queryResult.getError(0)));
        // Note: Listener is removed in finally below.
        } else if (isTerminalResult) {
            try {
                resultsListener.queryCompleted(queryState);
            } catch (Exception e) {
                resultsListener.submissionFailed(UserException.systemError(e).build(logger));
            }
        } else {
            logger.warn("queryState {} was ignored", queryState);
        }
    } finally {
        if (isTerminalResult) {
            // for it?
            if ((!(resultsListener instanceof BufferingResultsListener) || ((BufferingResultsListener) resultsListener).output != null)) {
                queryIdToResultsListenersMap.remove(queryId, resultsListener);
            }
        }
    }
}
Also used : QueryResult(org.apache.drill.exec.proto.UserBitShared.QueryResult) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) QueryState(org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState) UserException(org.apache.drill.common.exceptions.UserException) RpcException(org.apache.drill.exec.rpc.RpcException) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException)

Aggregations

UserException (org.apache.drill.common.exceptions.UserException)1 UserRemoteException (org.apache.drill.common.exceptions.UserRemoteException)1 QueryId (org.apache.drill.exec.proto.UserBitShared.QueryId)1 QueryResult (org.apache.drill.exec.proto.UserBitShared.QueryResult)1 QueryState (org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState)1 RpcException (org.apache.drill.exec.rpc.RpcException)1