TGetOperationStatusResp waitForOperationToComplete() throws SQLException {
    TGetOperationStatusResp statusResp = null;

    final TGetOperationStatusReq statusReq = new TGetOperationStatusReq(stmtHandle.get());
    statusReq.setGetProgressUpdate(inPlaceUpdateStream.isPresent());

    // Progress bar is completed if there is nothing to request
    if (inPlaceUpdateStream.isPresent()) {
      inPlaceUpdateStream.get().getEventNotifier().progressBarCompleted();
    }

    LOG.debug("Waiting on operation to complete: Polling operation status");

    // Poll on the operation status, till the operation is complete
    do {
      try {
        if (Thread.currentThread().isInterrupted()) {
          throw new SQLException(CLIENT_POLLING_OPSTATUS_INTERRUPTED.getMsg(),
              CLIENT_POLLING_OPSTATUS_INTERRUPTED.getSQLState());
        }
        /**
         * For an async SQLOperation, GetOperationStatus will use the long polling approach It will
         * essentially return after the HIVE_SERVER2_LONG_POLLING_TIMEOUT (a server config) expires
         */
        statusResp = client.GetOperationStatus(statusReq);
        LOG.debug("Status response: {}", statusResp);
        if (!isOperationComplete && inPlaceUpdateStream.isPresent()) {
          inPlaceUpdateStream.get().update(statusResp.getProgressUpdateResponse());
        }
        Utils.verifySuccessWithInfo(statusResp.getStatus());
        if (statusResp.isSetOperationState()) {
          switch (statusResp.getOperationState()) {
          case CLOSED_STATE:
          case FINISHED_STATE:
            isOperationComplete = true;
            isLogBeingGenerated = false;
            break;
          case CANCELED_STATE:
            // 01000 -> warning
            final String errMsg = statusResp.getErrorMessage();
            final String fullErrMsg =
                (errMsg == null || errMsg.isEmpty()) ? QUERY_CANCELLED_MESSAGE : QUERY_CANCELLED_MESSAGE + " " + errMsg;
            throw new SQLException(fullErrMsg, "01000");
          case TIMEDOUT_STATE:
            throw new SQLTimeoutException("Query timed out after " + queryTimeout + " seconds");
          case ERROR_STATE:
            // Get the error details from the underlying exception
            throw new SQLException(statusResp.getErrorMessage(), statusResp.getSqlState(),
                statusResp.getErrorCode());
          case UKNOWN_STATE:
            throw new SQLException("Unknown query", "HY000");
          case INITIALIZED_STATE:
          case PENDING_STATE:
          case RUNNING_STATE:
            break;
          }
        }
      } catch (SQLException e) {
        isLogBeingGenerated = false;
        throw e;
      } catch (Exception e) {
        isLogBeingGenerated = false;
        throw new SQLException("Failed to wait for operation to complete", "08S01", e);
      }
    } while (!isOperationComplete);

    // set progress bar to be completed when hive query execution has completed
    if (inPlaceUpdateStream.isPresent()) {
      inPlaceUpdateStream.get().getEventNotifier().progressBarCompleted();
    }
    return statusResp;
  }
Poll the result set status by checking if isSetHasResultSet is set
@return
@throws SQLException
jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java