public void clear(boolean deleteResultDir) throws IOException {
    // First clear the other contexts created by this query
    for (Context subContext : subContexts) {
      subContext.clear();
    }
    // Then clear this context
      if (resDir != null && !isInScratchDir(resDir)) { // resDir is inside the scratch dir, removeScratchDir will take care of removing it
        try {
          FileSystem fs = resDir.getFileSystem(conf);
          LOG.debug("Deleting result dir: {}", resDir);
          fs.delete(resDir, true);
        } catch (IOException e) {
          LOG.info("Context clear error", e);
        }
      }

    if (resFile != null && !isInScratchDir(resFile.getParent())) { // resFile is inside the scratch dir, removeScratchDir will take care of removing it
      try {
        FileSystem fs = resFile.getFileSystem(conf);
        LOG.debug("Deleting result file: {}",  resFile);
        fs.delete(resFile, false);
      } catch (IOException e) {
        LOG.info("Context clear error", e);
      }
    }
    if(deleteResultDir) {
      removeResultCacheDir();
    }
    removeMaterializedCTEs();
    removeScratchDir();
    originalTracker = null;
    setNeedLockMgr(false);
  }
@param resDir
         the resDir to set
ql/src/java/org/apache/hadoop/hive/ql/Context.java