@Override
  public RowSet getNextRowSet(FetchOrientation orientation, long maxRows)
    throws HiveSQLException {

    validateDefaultFetchOrientation(orientation);
    assertState(Collections.singleton(OperationState.FINISHED));

    FetchTask fetchTask = driver.getFetchTask();
    boolean isBlobBased = false;

    if (fetchTask != null && fetchTask.getWork().isUsingThriftJDBCBinarySerDe()) {
      // Just fetch one blob if we've serialized thrift objects in final tasks
      maxRows = 1;
      isBlobBased = true;
    }
    RowSet rowSet = RowSetFactory.create(getResultSetSchema(), getProtocolVersion(), isBlobBased);
    try {
      /* if client is requesting fetch-from-start and its not the first time reading from this operation
       * then reset the fetch position to beginning
       */
      if (orientation.equals(FetchOrientation.FETCH_FIRST) && fetchStarted) {
        driver.resetFetch();
      }
      fetchStarted = true;

      final int capacity = Math.toIntExact(maxRows);
      convey.ensureCapacity(capacity);
      driver.setMaxRows(capacity);
      if (driver.getResults(convey)) {
        if (convey.size() == capacity) {
          log.info("Result set buffer filled to capacity [{}]", capacity);
        }
        return decode(convey, rowSet);
      }
      return rowSet;
    } catch (Exception e) {
      throw new HiveSQLException("Unable to get the next row set with exception: " + e.getMessage(), e, queryState.getQueryId());
    } finally {
      convey.clear();
    }
  }
Returns the current UGI on the stack

@return UserGroupInformation

@throws HiveSQLException
service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java