public Path getMRScratchDir(boolean mkDir) {
    // if we are executing entirely on the client side - then
    // just (re)use the local scratch directory
    if(isLocalOnlyExecutionMode()) {
      return getLocalScratchDir(mkDir);
    }

    try {
      Path dir = FileUtils.makeQualified(nonLocalScratchPath, conf);
      URI uri = dir.toUri();

      Path newScratchDir = getScratchDir(uri.getScheme(), uri.getAuthority(),
                                         mkDir, uri.getPath());
      LOG.info("New scratch dir is " + newScratchDir);
      return newScratchDir;
    } catch (IOException e) {
      throw new RuntimeException(e);
    } catch (IllegalArgumentException e) {
      throw new RuntimeException("Error while making MR scratch "
                                     + "directory - check filesystem config (" + e.getCause() + ")", e);
    }
  }
Create a map-reduce scratch directory on demand and return it.
@param mkDir flag to indicate if scratch dir is to be created or not
ql/src/java/org/apache/hadoop/hive/ql/Context.java