package com.twitter.elephantbird.mapreduce.output;

import java.io.IOException;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

public interface WorkFileOverride {
  public static abstract class FileOutputFormat<K, V>
      extends org.apache.hadoop.mapreduce.lib.output.FileOutputFormat<K, V> implements WorkFileOverride {

    private String name;

    @Override
    public Path getDefaultWorkFile(TaskAttemptContext context, String extension) throws IOException {
      if (name == null) {
        return super.getDefaultWorkFile(context, extension);
      } else {
        return WorkFileOverride.Method.getDefaultWorkFileOverride(this, name, context, extension);
      }
    }

    @Override public void setName(String name) { this.name = name; }
  }

  public static abstract class TextOutputFormat<K, V>
      extends org.apache.hadoop.mapreduce.lib.output.TextOutputFormat<K, V> implements WorkFileOverride {

    private String name;

    @Override
    public Path getDefaultWorkFile(TaskAttemptContext context, String extension) throws IOException {
      if (name == null) {
        return super.getDefaultWorkFile(context, extension);
      } else {
        return WorkFileOverride.Method.getDefaultWorkFileOverride(this, name, context, extension);
      }
    }

    @Override public void setName(String name) { this.name = name; }
  }

  public static class Method {
    private Method() {
    }

    public static Path getDefaultWorkFileOverride(
      org.apache.hadoop.mapreduce.lib.output.FileOutputFormat<?, ?> outputFormat,
      String name,
      TaskAttemptContext context,
      String extension
    ) throws IOException {
      FileOutputCommitter committer = (FileOutputCommitter) outputFormat.getOutputCommitter(context);
      return new Path(committer.getWorkPath(), name + extension);
    }
  }

  void setName(String name);
}

@@ -299,43 +299,1324 @@
 t;%0A%0A
-public interface WorkFileOverride %7B
+/**%0A * This is a class to deal with the different handling of subpaths in the mapred%0A * and mapreduce api. The WorkFileOverride interface is used by the%0A * %7B@link DeprecatedFileOutputFormatWrapper%7D in order to know whether a name%0A * has been passed to%0A * %7B@link org.apache.hadoop.mapred.OutputFormat#getRecordWriter(FileSystem, JobConf, String, Progressable%7D.%0A * Historically, these were thrown away which was ok except in the case where%0A * a map reduce job wanted to write to multiple sub-directories in the base%0A * path. Using the WorkFileOverride will make it so that this is possible.%0A * This is achieved by overriding%0A * %7B@link org.apache.hadoop.mapreduce.OutputFormat#getDefaultWorkFile(TaskAttemptContext, String%7D%7D and%0A * incoroprating a name variable. the %7B@link #setName()%7D method serves as a hook so that the%0A * %7B@link DeprecatedFileOutputFormatWrapper%7D can pass the name from the mapred api to the mapreduce API.%0A *%0A * @author Jonathan Coveney%0A */%0Apublic interface WorkFileOverride %7B%0A  /**%0A   * This is an abstract base class that users can drop in as a replacement for%0A   * using the normal FileOutputFormat as a base class in order to make the%0A   * extending subclass usable with %7B@link DeprecatedFileOutputFormatWrapper%7D.%0A   *%0A   * %7B@see com.twitter.elephantbird.mapreduce.output.LzoOutputFormat%7D%0A   */
 %0A  p
@@ -2197,32 +2197,358 @@
  = name; %7D%0A  %7D%0A%0A
+  /**%0A   * This is an abstract base class that users can drop in as a replacement for%0A   * using the normal TextOutputFormat as a base class in order to make the%0A   * extending subclass usable with %7B@link DeprecatedFileOutputFormatWrapper%7D.%0A   *%0A   * %7B@see com.twitter.elephantbird.mapreduce.output.LzoTextOutputFormat%7D%0A   */%0A
   public static 
@@ -3124,16 +3124,177 @@
  %7D%0A  %7D%0A%0A
+  /**%0A   * This class is a helper to minimize the amount of logic to implement for%0A   * a given FileOutputFormat that wants to implement WorkFileOverride.%0A   */%0A
   public
@@ -3761,16 +3761,91 @@
  %7D%0A  %7D%0A%0A
+  /**%0A   * This is the hook for a OutputFormat to pass in a subpath.%0A   */%0A
   void s

Add documentation