Author: cutting Date: Fri Mar 30 10:11:24 2007 New Revision: 524181 URL: http://svn.apache.org/viewvc?view=rev&rev=524181 Log: HADOOP-1166. Add a NullOutputFormat and use it in the RandomWriter example. Contributed by Owen.
Added: lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/lib/NullOutputFormat.java Modified: lucene/hadoop/trunk/CHANGES.txt lucene/hadoop/trunk/src/examples/org/apache/hadoop/examples/RandomWriter.java Modified: lucene/hadoop/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=524181&r1=524180&r2=524181 ============================================================================== --- lucene/hadoop/trunk/CHANGES.txt (original) +++ lucene/hadoop/trunk/CHANGES.txt Fri Mar 30 10:11:24 2007 @@ -58,6 +58,9 @@ 17. HADOOP-1164. Fix TestReplicationPolicy to specify port zero, so that a free port is automatically selected. (omalley via cutting) +18. HADOOP-1166. Add a NullOutputFormat and use it in the + RandomWriter example. (omalley via cutting) + Release 0.12.3 (not yet released) Modified: lucene/hadoop/trunk/src/examples/org/apache/hadoop/examples/RandomWriter.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/examples/org/apache/hadoop/examples/RandomWriter.java?view=diff&rev=524181&r1=524180&r2=524181 ============================================================================== --- lucene/hadoop/trunk/src/examples/org/apache/hadoop/examples/RandomWriter.java (original) +++ lucene/hadoop/trunk/src/examples/org/apache/hadoop/examples/RandomWriter.java Fri Mar 30 10:11:24 2007 @@ -28,7 +28,7 @@ import org.apache.hadoop.io.SequenceFile.CompressionType; import org.apache.hadoop.mapred.*; import org.apache.hadoop.mapred.lib.IdentityReducer; -import org.apache.hadoop.util.Progressable; +import org.apache.hadoop.mapred.lib.NullOutputFormat; /** * This program uses map/reduce to just run a distributed job where there is @@ -107,20 +107,6 @@ } } - /** - * Consume all outputs and put them in /dev/null. - */ - static class DataSink implements OutputFormat { - public RecordWriter getRecordWriter(FileSystem ignored, JobConf job, - String name, Progressable progress) { - return new RecordWriter(){ - public void write(WritableComparable key, Writable value) { } - public void close(Reporter reporter) { } - }; - } - public void checkOutputSpecs(FileSystem ignored, JobConf job) { } - } - static class Map extends MapReduceBase implements Mapper { private FileSystem fileSys = null; private JobConf jobConf = null; @@ -202,14 +188,6 @@ * It runs 10 maps/node and each node writes 1 gig of data to a DFS file. * The reduce doesn't do anything. * - * This program uses a useful pattern for dealing with Hadoop's constraints - * on InputSplits. Since each input split can only consist of a file and - * byte range and we want to control how many maps there are (and we don't - * really have any inputs), we create a directory with a set of artificial - * files that each contain the filename that we want a given map to write - * to. Then, using the text line reader and this "fake" input directory, we - * generate exactly the right number of maps. Each map gets a single record - * that is the filename it is supposed to write its output to. * @throws IOException */ public static void main(String[] args) throws IOException { @@ -237,7 +215,7 @@ job.setInputFormat(RandomInputFormat.class); job.setMapperClass(Map.class); job.setReducerClass(IdentityReducer.class); - job.setOutputFormat(DataSink.class); + job.setOutputFormat(NullOutputFormat.class); JobClient client = new JobClient(job); ClusterStatus cluster = client.getClusterStatus(); Added: lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/lib/NullOutputFormat.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/lib/NullOutputFormat.java?view=auto&rev=524181 ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/lib/NullOutputFormat.java (added) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/lib/NullOutputFormat.java Fri Mar 30 10:11:24 2007 @@ -0,0 +1,43 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.mapred.lib; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.io.Writable; +import org.apache.hadoop.io.WritableComparable; +import org.apache.hadoop.mapred.JobConf; +import org.apache.hadoop.mapred.OutputFormat; +import org.apache.hadoop.mapred.RecordWriter; +import org.apache.hadoop.mapred.Reporter; +import org.apache.hadoop.util.Progressable; + +/** + * Consume all outputs and put them in /dev/null. + */ +public class NullOutputFormat implements OutputFormat { + public RecordWriter getRecordWriter(FileSystem ignored, JobConf job, + String name, Progressable progress) { + return new RecordWriter(){ + public void write(WritableComparable key, Writable value) { } + public void close(Reporter reporter) { } + }; + } + + public void checkOutputSpecs(FileSystem ignored, JobConf job) { } +}