



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















So far, we've been protected from the full complexity of hadoop by using Pig. Let's see what we've been missing! Yahoo's open-source MapReduce implementation Reference: http://developer.yahoo.com/hadoop/tutorial/ Hadoop A distributed file system (HDFS) that can store large amounts of data A Map/Reduce programming model that enables scalable data processing. Two main parts Using Raw Hadoop Sunday, February 28, 2010 8:34 AM Docsity.com
A distributed filesystem that makes data available to multiple compute nodes. A driver that institutes the MapReduce operation. A mapper that reads data and maps it. A combiner that reduces the size of mapped data. A reducer that summarizes and stores results in the HDFS filesystem. Components of a hadoop application Note: the output is not a stream , but rather, a distributed file. Components of a hadoop application Sunday, February 28, 2010 12:44 PM Docsity.com
we describe a typical hadoop example in which mapper workers are also reducer workers. For simplicity, Trackers that start a job and finish it. Mappers that contain HDFS and do the operation. Reducers that don't contain HDFS and find final results. In fact, in a real Hadoop implementation, you need to declare three kinds of nodes: For simplicity Monday, March 01, 2010 5:11 PM Docsity.com
put map shuffle reduce get Often, the same nodes are mappers and reducers. This picture is a bit deceptive, because phases begin asynchronously. If one mapper gets done mapping early, it will start shuffling before the others. Combiner can reduce data during the shuffle; reducer is called after shuffling is complete. Worker 1 Worker 4 Worker 2 Worker 3 A picture of Hadoop MapReduce Processing Monday, March 01, 2010 3:07 PM Docsity.com
Number processors 0-n. Map each key to hash h(k) between 0 and n. if k is at processor p and h(k) differs from p in the sth bit, send <k,v> to processor p^(1<<s) (^=xor). At step s (from 0 to log2(n)), Understanding butterfly sort Suppose key k is at worker 0=000 2 and needs to be at worker 5=h(k)=101 2 in binary First worker 0=000 2 sends it to worker 1 = 001 2. Then worker 1=001 2 sends it to worker 5 = 101 2. Theorem: a key always gets to its intended destination in O(log(N)) steps, where N is the number of workers. Example of shuffle sort Monday, March 01, 2010 4:46 PM Docsity.com
Input: a set of text files, concatenated into a big text file Mapper : for each word w, generate pairs <word, 1>, where w is a key. Reducer : for each w, sum up 1's to get count of that word. Driver : orchestrate calling mapper/reducer. An example application: word count An example application Sunday, February 28, 2010 1:24 PM Docsity.com
Input: shards (fragments) of the text to be counted. Output: a list of <w,1> pairs for w a word. The mapper // a value of 1 of the appropriate type for reducing private final IntWritable one = new IntWritable(1); public void map(WritableComparable key, Writable value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException { // WritableComparable means one can apply >, =, < to it. // Writable means that one can write it, // but might not be able to compare it. // WritableComparable is a subinterface of Writable. // each line is a shard, as a string. String line = value.toString(); // break line into a sequence of tokens StringTokenizer itr = new StringTokenizer(line.toLowerCase()); // iterate over tokens. while(itr.hasMoreTokens()) { word.set(itr.nextToken()); output.collect(word, one); // add one! } } The mapper Sunday, February 28, 2010 8:43 PM Docsity.com
public void map(WritableComparable key, Writable value, OutputCollector<Text, IntWritable> output, Reporter reporter) Taking the mapper apart: an interface requiring support for set, <, ==, >. WritableComparable: an interface requiring support for just set. Writable: (WritableComparable extends Writable) a place to put output from the mapping process, e.g., via output.collect(word, one) OutputCollector: a way to communicate problems to the user. Reporter: Taking the mapper apart Sunday, February 28, 2010 8:51 PM Docsity.com
Accepts <w, 1> pairs. Sums up the 1's. The reducer: public void reduce(Text key, Iterator
OutputCollector<Text,IntWritable> output, Reporter reporter) public void reduce(Text key, Iterator
A driver public static void main(String[] args) { // Create a "configuration" for a job JobConf conf = new JobConf(WordCount.class); // specify output types conf.setOutputKeyClass(Text.class); conf.setOutputValueClass(IntWritable.class); // specify input and output directories in filesystem FileInputPath.addInputPath(conf, new Path("input")); FileOutputPath.addOutputPath(conf, new Path("output")); // specify a mapper conf.setMapperClass( WordCountMapper .class); // a reducer produces a final answer. conf.setReducerClass( WordCountReducer .class); // a combiner produces intermediate values. conf.setCombinerClass( WordCountReducer .class); try { // try to do it. JobClient.runJob(conf); } catch (Exception e) { e.printStackTrace(); } } A driver Sunday, February 28, 2010 9:07 PM Docsity.com
Creating a "job" for the Hadoop cluster: // Create a "configuration" for a job JobConf conf = new JobConf(WordCount.class); // ⦠set configuration parts Taking the driver apart try { // try to do it. JobClient.runJob(conf); } catch (Exception e) { e.printStackTrace(); } Taking the driver apart Sunday, February 28, 2010 9:12 PM Docsity.com
IntWritable is an integer that is writable. LongWritable likewise. Data are contained in "smart containers" Keys must be Comparable. Values must be Writable. Some finer points Some finer points Sunday, February 28, 2010 9:46 PM Docsity.com
Writable WritableComparable IntWritable LongWritable Text extends implements The interface hierarchy Monday, March 01, 2010 10:31 AM Docsity.com