private void releaseContext() {
    try {
      if (context != null) {
        boolean deleteResultDir = true;
        // don't let context delete result dirs and scratch dirs if result was cached
        if (driverContext.getCacheUsage() != null
            && driverContext.getCacheUsage().getStatus() == CacheUsage.CacheStatus.QUERY_USING_CACHE) {
          deleteResultDir = false;

        }
        context.clear(deleteResultDir);
        if (context.getHiveLocks() != null) {
          driverTxnHandler.addHiveLocksFromContext();
          context.setHiveLocks(null);
        }
        context = null;
      }

      if (SessionState.get() != null) {
        QueryState queryState = getQueryState();
        // If the driver object is reused for several queries, make sure we empty the HMS query cache
        Map<Object, Object> queryCache = SessionState.get().getQueryCache(queryState.getQueryId());
        if (queryCache != null) {
          queryCache.clear();
        }
        queryState.disableHMSCache();
        // Reset the resourceMap to ensure that previous execution's data is not reused during a retry.
        queryState.clearResourceMap();
        // Remove any query state reference from the session state
        SessionState.get().removeQueryState(queryState.getQueryId());
      }
    } catch (Exception e) {
      LOG.debug("Exception while clearing the context ", e);
    }
  }
Set the maximum number of rows returned by getResults.
ql/src/java/org/apache/hadoop/hive/ql/Driver.java