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.lib.output; 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.mapreduce.JobContext; 026 import org.apache.hadoop.mapreduce.OutputCommitter; 027 import org.apache.hadoop.mapreduce.OutputFormat; 028 import org.apache.hadoop.mapreduce.RecordWriter; 029 import org.apache.hadoop.mapreduce.TaskAttemptContext; 030 031 /** 032 * Consume all outputs and put them in /dev/null. 033 */ 034 @InterfaceAudience.Public 035 @InterfaceStability.Stable 036 public 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 @Deprecated 064 public boolean isRecoverySupported() { 065 return true; 066 } 067 068 @Override 069 public void recoverTask(TaskAttemptContext taskContext) 070 throws IOException { 071 // Nothing to do for recovering the task. 072 } 073 }; 074 } 075 }