001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    
019    package org.apache.hadoop.mapreduce;
020    
021    import java.io.IOException;
022    
023    import org.apache.hadoop.classification.InterfaceAudience;
024    import org.apache.hadoop.classification.InterfaceStability;
025    import org.apache.hadoop.fs.FileSystem;
026    
027    /** 
028     * <code>OutputFormat</code> describes the output-specification for a 
029     * Map-Reduce job.
030     *
031     * <p>The Map-Reduce framework relies on the <code>OutputFormat</code> of the
032     * job to:<p>
033     * <ol>
034     *   <li>
035     *   Validate the output-specification of the job. For e.g. check that the 
036     *   output directory doesn't already exist. 
037     *   <li>
038     *   Provide the {@link RecordWriter} implementation to be used to write out
039     *   the output files of the job. Output files are stored in a 
040     *   {@link FileSystem}.
041     *   </li>
042     * </ol>
043     * 
044     * @see RecordWriter
045     */
046    @InterfaceAudience.Public
047    @InterfaceStability.Stable
048    public abstract class OutputFormat<K, V> {
049    
050      /** 
051       * Get the {@link RecordWriter} for the given task.
052       *
053       * @param context the information about the current task.
054       * @return a {@link RecordWriter} to write the output for the job.
055       * @throws IOException
056       */
057      public abstract RecordWriter<K, V> 
058        getRecordWriter(TaskAttemptContext context
059                        ) throws IOException, InterruptedException;
060    
061      /** 
062       * Check for validity of the output-specification for the job.
063       *  
064       * <p>This is to validate the output specification for the job when it is
065       * a job is submitted.  Typically checks that it does not already exist,
066       * throwing an exception when it already exists, so that output is not
067       * overwritten.</p>
068       *
069       * @param context information about the job
070       * @throws IOException when output should not be attempted
071       */
072      public abstract void checkOutputSpecs(JobContext context
073                                            ) throws IOException, 
074                                                     InterruptedException;
075    
076      /**
077       * Get the output committer for this output format. This is responsible
078       * for ensuring the output is committed correctly.
079       * @param context the task context
080       * @return an output committer
081       * @throws IOException
082       * @throws InterruptedException
083       */
084      public abstract 
085      OutputCommitter getOutputCommitter(TaskAttemptContext context
086                                         ) throws IOException, InterruptedException;
087    }
088