code: protected String getInputFileBasedOutputFileName(JobConf job, String name) {
      String infilepath = job.get("map.input.file");
      if (infilepath == null) {
        // if the map input file does not exists, then return the given name
        return name;
      }
      int numOfTrailingLegsToUse = job.getInt("mapred.outputformat.numOfTrailingLegs", 0);
      if (numOfTrailingLegsToUse <= 0) {
        return name;
      }
      Path infile = new Path(infilepath);
      Path parent = infile.getParent();
      String midName = infile.getName();
      Path outPath = new Path(midName);
      for (int i = 1; i < numOfTrailingLegsToUse; i++) {
        if (parent == null) break;
        midName = parent.getName();
        if (midName.length() == 0) break;
        parent = parent.getParent();
        outPath = new Path(midName, outPath);
      }
      return outPath.toString();
    }
docs: Generate the outfile name based on a given anme and the input file name. If
  the map input file does not exists (i.e. this is not for a map only job),
  the given name is returned unchanged. If the config value for
  "num.of.trailing.legs.to.use" is not set, or set 0 or negative, the given
  name is returned unchanged. Otherwise, return a file name consisting of the
  N trailing legs of the input file name where N is the config value for
  "num.of.trailing.legs.to.use".
  
  @param job
  the job config
  @param name
  the output file name
  @return the outfile name based on a given anme and the input file name.