@SuppressWarnings({ "unchecked", "rawtypes" })
  @Override
  public boolean getResults(List results) throws IOException {
    if (driverState.isDestroyed() || driverState.isClosed()) {
      throw new IOException("FAILED: query has been cancelled, closed, or destroyed.");
    }

    if (isFetchingTable()) {
      return getFetchingTableResults(results);
    }

    if (driverContext.getResStream() == null) {
      // If the driver does not have a stream and neither does the context, return
      DataInput contextStream = context.getStream();
      if (contextStream == null) {
        return false;
      }
      driverContext.setResStream(contextStream);
    }

    int numRows = 0;
    ByteStream.Output bos = new ByteStream.Output();
    while (numRows < maxRows) {
      if (driverContext.getResStream() == null) {
        return (numRows > 0);
      }

      bos.reset();
      Utilities.StreamStatus streamStatus;
      try {
        streamStatus = Utilities.readColumn(driverContext.getResStream(), bos);
        String row = getRow(bos, streamStatus);
        if (row != null) {
          numRows++;
          results.add(row);
        }
      } catch (IOException e) {
        CONSOLE.printError("FAILED: Unexpected IO exception : " + e.getMessage());
        return false;
      }

      if (streamStatus == Utilities.StreamStatus.EOF) {
        driverContext.setResStream(context.getStream());
      }
    }
    return true;
  }
Set the maximum number of rows returned by getResults.
ql/src/java/org/apache/hadoop/hive/ql/Driver.java