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.mapreduce.lib.output;
020
021import java.io.IOException;
022
023import org.apache.hadoop.classification.InterfaceAudience;
024import org.apache.hadoop.classification.InterfaceStability;
025import org.apache.hadoop.mapreduce.JobContext;
026import org.apache.hadoop.mapreduce.OutputCommitter;
027import org.apache.hadoop.mapreduce.OutputFormat;
028import org.apache.hadoop.mapreduce.RecordWriter;
029import org.apache.hadoop.mapreduce.TaskAttemptContext;
030
031/**
032 * Consume all outputs and put them in /dev/null. 
033 */
034@InterfaceAudience.Public
035@InterfaceStability.Stable
036public class NullOutputFormat<K, V> extends OutputFormat<K, V> {
037  
038  @Override
039  public RecordWriter<K, V> 
040         getRecordWriter(TaskAttemptContext context) {
041    return new RecordWriter<K, V>(){
042        public void write(K key, V value) { }
043        public void close(TaskAttemptContext context) { }
044      };
045  }
046  
047  @Override
048  public void checkOutputSpecs(JobContext context) { }
049  
050  @Override
051  public OutputCommitter getOutputCommitter(TaskAttemptContext context) {
052    return new OutputCommitter() {
053      public void abortTask(TaskAttemptContext taskContext) { }
054      public void cleanupJob(JobContext jobContext) { }
055      public void commitTask(TaskAttemptContext taskContext) { }
056      public boolean needsTaskCommit(TaskAttemptContext taskContext) {
057        return false;
058      }
059      public void setupJob(JobContext jobContext) { }
060      public void setupTask(TaskAttemptContext taskContext) { }
061
062      @Override
063      public boolean isRecoverySupported() {
064        return true;
065      }
066
067      @Override
068      public void recoverTask(TaskAttemptContext taskContext)
069          throws IOException {
070        // Nothing to do for recovering the task.
071      }
072    };
073  }
074}