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 019package org.apache.hadoop.mapred; 020 021import java.io.IOException; 022 023import org.apache.hadoop.classification.InterfaceAudience; 024import org.apache.hadoop.classification.InterfaceStability; 025import org.apache.hadoop.fs.FileSystem; 026import org.apache.hadoop.util.Progressable; 027 028/** 029 * <code>OutputFormat</code> describes the output-specification for a 030 * Map-Reduce job. 031 * 032 * <p>The Map-Reduce framework relies on the <code>OutputFormat</code> of the 033 * job to:<p> 034 * <ol> 035 * <li> 036 * Validate the output-specification of the job. For e.g. check that the 037 * output directory doesn't already exist. 038 * <li> 039 * Provide the {@link RecordWriter} implementation to be used to write out 040 * the output files of the job. Output files are stored in a 041 * {@link FileSystem}. 042 * </li> 043 * </ol> 044 * 045 * @see RecordWriter 046 * @see JobConf 047 */ 048@InterfaceAudience.Public 049@InterfaceStability.Stable 050public interface OutputFormat<K, V> { 051 052 /** 053 * Get the {@link RecordWriter} for the given job. 054 * 055 * @param ignored 056 * @param job configuration for the job whose output is being written. 057 * @param name the unique name for this part of the output. 058 * @param progress mechanism for reporting progress while writing to file. 059 * @return a {@link RecordWriter} to write the output for the job. 060 * @throws IOException 061 */ 062 RecordWriter<K, V> getRecordWriter(FileSystem ignored, JobConf job, 063 String name, Progressable progress) 064 throws IOException; 065 066 /** 067 * Check for validity of the output-specification for the job. 068 * 069 * <p>This is to validate the output specification for the job when it is 070 * a job is submitted. Typically checks that it does not already exist, 071 * throwing an exception when it already exists, so that output is not 072 * overwritten.</p> 073 * 074 * @param ignored 075 * @param job job configuration. 076 * @throws IOException when output should not be attempted 077 */ 078 void checkOutputSpecs(FileSystem ignored, JobConf job) throws IOException; 079} 080