Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
201109%
01-1
Chapter 1
Introduction
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
01-2
Introduction
About This Course
About Cloudera
Course Logistics
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
01-3
Course Objectives
During this course, you will learn:
The core technologies of Hadoop
How HDFS and MapReduce work
What other projects exist in the Hadoop ecosystem
How to develop MapReduce jobs
Algorithms for common MapReduce tasks
How to create large workflows using multiple MapReduce jobs
Best practices for debugging Hadoop jobs
Advanced features of the Hadoop API
How to handle graph manipulation problems with MapReduce
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
01-4
Course Chapters
Introduction
The Motivation For Hadoop
Hadoop: Basic Contents
Writing a MapReduce Program
The Hadoop Ecosystem
Integrating Hadoop Into The Workflow
Delving Deeper Into The Hadoop API
Common MapReduce Algorithms
An Introduction to Hive and Pig
Debugging MapReduce Programs
Advanced MapReduce Programming
Joining Data Sets in MapReduce Jobs
Graph Manipulation In MapReduce
Conclusion
Appendix: Cloudera Enterprise
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
01-5
Introduction
About This Course
About Cloudera
Course Logistics
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
01-6
About Cloudera
Cloudera is The commercial Hadoop company
Founded by leading experts on Hadoop from Facebook, Google,
Oracle and Yahoo
Provides consulting and training services for Hadoop users
Staff includes several committers to Hadoop projects
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
01-7
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
01-8
Cloudera Services
Provides consultancy services to many key users of Hadoop
Including AOL Advertising, Samsung, Groupon, NAVTEQ, Trulia,
Tynt, RapLeaf, Explorys Medical
Solutions Architects are experts in Hadoop and related
technologies
Several are committers to the Apache Hadoop project
Provides training in key areas of Hadoop administration and
Development
Courses include System Administrator training, Developer
training, Data Analysis with Hive and Pig, HBase Training,
Essentials for Managers
Custom course development available
Both public and on-site training available
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
01-9
Cloudera Enterprise
Cloudera Enterprise
Complete package of software and support
Built on top of CDH
Includes tools for monitoring the Hadoop cluster
Resource consumption tracking
Quota management
Etc
Includes management tools
Authorization management and provisioning
Integration with LDAP
Etc
24 x 7 support
More information in Appendix A
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
01-10
Introduction
About This Course
About Cloudera
Course Logistics
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
01-11
Logistics
Course start and end times
Lunch
Breaks
Restrooms
Can I come in early/stay late?
Certification
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
01-12
Introductions
About your instructor
About you
Experience with Hadoop?
Experience as a developer?
What programming languages do you use?
Expectations from the course?
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
01-13
Chapter 2
The Motivation For Hadoop
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-1
Course Chapters
Introduction
The Motivation For Hadoop
Hadoop: Basic Contents
Writing a MapReduce Program
The Hadoop Ecosystem
Integrating Hadoop Into The Workflow
Delving Deeper Into The Hadoop API
Common MapReduce Algorithms
An Introduction to Hive and Pig
Debugging MapReduce Programs
Advanced MapReduce Programming
Joining Data Sets in MapReduce Jobs
Graph Manipulation In MapReduce
Conclusion
Appendix: Cloudera Enterprise
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-2
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-3
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-4
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-5
Distributed Systems
Moores Law: roughly stated, processing power doubles every
two years
Even that hasnt always proved adequate for very CPU-intensive
jobs
Distributed systems evolved to allow developers to use multiple
machines for a single job
MPI
PVM
Condor
02-6
02-7
02-8
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-9
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-10
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-11
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-12
Data Recoverability
If a component of the system fails, its workload should be
assumed by still-functioning units in the system
Failure should not result in the loss of any data
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-13
Component Recovery
If a component of the system fails and then recovers, it should
be able to rejoin the system
Without requiring a full restart of the entire system
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-14
Consistency
Component failures during execution of a job should not affect
the outcome of the job
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-15
Scalability
Adding load to the system should result in a graceful decline in
performance of individual jobs
Not failure of the system
Increasing resources should support a proportional increase in
load capacity
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-16
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-17
Hadoops History
Hadoop is based on work done by Google in the late 1990s/early
2000s
Specifically, on papers describing the Google File System (GFS)
published in 2003, and MapReduce published in 2004
This work takes a radical new approach to the problem of
distributed computing
Meets all the requirements we have for reliability, scalability etc
Core concept: distribute the data as it is initially stored in the
system
Individual nodes can work on data local to those nodes
No data transfer over the network is required for initial
processing
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-18
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-19
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-20
Fault Tolerance
If a node fails, the master will detect that failure and re-assign the
work to a different node on the system
Restarting a task does not require communication with nodes
working on other portions of the data
If a failed node restarts, it is automatically added back to the
system and assigned new tasks
If a node appears to be running slowly, the master can
redundantly execute another instance of the same task
Results from the first to finish will be used
Known as speculative execution
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-21
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-22
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
02-23
Chapter 3
Hadoop: Basic Concepts
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-1
Course Chapters
Introduction
The Motivation For Hadoop
Hadoop: Basic Contents
Writing a MapReduce Program
The Hadoop Ecosystem
Integrating Hadoop Into The Workflow
Delving Deeper Into The Hadoop API
Common MapReduce Algorithms
An Introduction to Hive and Pig
Debugging MapReduce Programs
Advanced MapReduce Programming
Joining Data Sets in MapReduce Jobs
Graph Manipulation In MapReduce
Conclusion
Appendix: Cloudera Enterprise
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-2
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-3
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-4
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-5
Hadoop Components
Hadoop consists of two core components
The Hadoop Distributed File System (HDFS)
MapReduce
There are many other projects based around core Hadoop
Often referred to as the Hadoop Ecosystem
Pig, Hive, HBase, Flume, Oozie, Sqoop, etc
Many are discussed later in the course
A set of machines running HDFS and MapReduce is known as a
Hadoop Cluster
Individual machines are known as nodes
A cluster can have as few as one node, as many as several
thousands
More nodes = better performance!
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-6
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-7
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-8
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-9
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-10
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-11
03-12
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-13
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-14
03-15
Accessing HDFS
Applications can read and write HDFS files directly via the Java
API
Covered later in the course
Typically, files are created on a local filesystem and must be
moved into HDFS
Likewise, files stored in HDFS may need to be moved to a
machines local filesystem
Access to HDFS from the command line is achieved with the
hadoop fs command
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-16
hadoop fs Examples
Copy file foo.txt from local disk to the users directory in HDFS
hadoop fs -copyFromLocal foo.txt foo.txt
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-17
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-18
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-19
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-20
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-21
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-22
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-23
What Is MapReduce?
MapReduce is a method for distributing a task across multiple
nodes
Each node processes data stored on that node
Where possible
Consists of two phases:
Map
Reduce
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-24
Features of MapReduce
Automatic parallelization and distribution
Fault-tolerance
Status and monitoring tools
A clean abstraction for programmers
MapReduce programs are usually written in Java
Can be written in any scripting language using Hadoop
Streaming (see later)
All of Hadoop is written in Java
MapReduce abstracts all the housekeeping away from the
developer
Developer can concentrate simply on writing the Map and
Reduce functions
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-25
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-26
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-27
MapReduce: Terminology
A job is a full program a complete execution of Mappers and
Reducers over a dataset
A task is the execution of a single Mapper or Reducer over a slice
of data
A task attempt is a particular instance of an attempt to execute a
task
There will be at least as many task attempts as there are tasks
If a task attempt fails, another will be started by the JobTracker
Speculative execution (see later) can also result in more task
attempts than completed tasks
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-28
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-29
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-30
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-31
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-32
('foo', 7) ->
('foo', 7)
nothing
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-33
(3, 'bar')
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-34
03-35
('foo', 39)
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-36
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-37
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-38
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-39
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-40
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-41
reduce(String output_key,
Iterator<int> intermediate_vals)
set count = 0
foreach v in intermediate_vals:
count += v
emit(output_key, count)
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-42
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-43
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-44
03-45
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-46
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-47
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-48
03-49
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-50
03-51
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-52
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-53
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-54
Submitting A Job
When a client submits a job, its configuration information is
packaged into an XML file
This file, along with the .jar file containing the actual program
code, is handed to the JobTracker
The JobTracker then parcels out individual tasks to TaskTracker
nodes
When a TaskTracker receives a request to run a task, it
instantiates a separate JVM for that task
TaskTracker nodes can be configured to run multiple tasks at the
same time
If the node has enough processing power and memory
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-55
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-56
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-57
Conclusion
In this chapter you have learned
What Hadoop is
What features the Hadoop Distributed File System (HDFS)
provides
The concepts behind MapReduce
How a Hadoop cluster operates
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
03-58
Chapter 4
Writing a MapReduce
Program
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-1
Course Chapters
Introduction
The Motivation For Hadoop
Hadoop: Basic Contents
Writing a MapReduce Program
The Hadoop Ecosystem
Integrating Hadoop Into The Workflow
Delving Deeper Into The Hadoop API
Common MapReduce Algorithms
An Introduction to Hive and Pig
Debugging MapReduce Programs
Advanced MapReduce Programming
Joining Data Sets in MapReduce Jobs
Graph Manipulation In MapReduce
Conclusion
Appendix: Cloudera Enterprise
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-2
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-3
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-4
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-5
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-6
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-7
org.apache.hadoop.fs.Path;
org.apache.hadoop.io.IntWritable;
org.apache.hadoop.io.Text;
org.apache.hadoop.mapred.FileInputFormat;
org.apache.hadoop.mapred.FileOutputFormat;
org.apache.hadoop.mapred.JobClient;
org.apache.hadoop.mapred.JobConf;
JobClient.runJob(conf);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-8
org.apache.hadoop.fs.Path;
org.apache.hadoop.io.IntWritable;
org.apache.hadoop.io.Text;
org.apache.hadoop.mapred.FileInputFormat;
org.apache.hadoop.mapred.FileOutputFormat;
org.apache.hadoop.mapred.JobClient;
org.apache.hadoop.mapred.JobConf;
JobClient.runJob(conf);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-9
JobClient.runJob(conf);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-10
JobClient.runJob(conf);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-11
JobClient.runJob(conf);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-12
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-13
conf.setMapperClass(WordMapper.class);
conf.setMapOutputKeyClass(Text.class);
conf.setMapOutputValueClass(IntWritable.class);
conf.setReducerClass(SumReducer.class);
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
JobClient.runJob(conf);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-14
JobClient.runJob(conf);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-15
04-16
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-17
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-18
04-19
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-20
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-21
Give
are
to be instantiated as the Mapper and Reducer. You also
JobConf conf = new JobConf(WordCount.class);
conf.setJobName("WordCount");
specify
the classes for the intermediate and final keys and
FileInputFormat.setInputPaths(conf,
new Path(args[0]));
values
(see later)
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
conf.setMapperClass(WordMapper.class);
conf.setMapOutputKeyClass(Text.class);
conf.setMapOutputValueClass(IntWritable.class);
conf.setReducerClass(SumReducer.class);
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
JobClient.runJob(conf);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-22
JobClient.runJob(conf);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-23
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-24
JobClient.runJob(conf);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-25
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-26
org.apache.hadoop.io.IntWritable;
org.apache.hadoop.io.Text;
org.apache.hadoop.mapred.Mapper;
org.apache.hadoop.mapred.MapReduceBase;
org.apache.hadoop.mapred.OutputCollector;
org.apache.hadoop.mapred.Reporter;
while (wordList.hasMoreTokens()) {
word.set(wordList.nextToken());
output.collect(word, one);
}
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-27
org.apache.hadoop.io.IntWritable;
org.apache.hadoop.io.Text;
org.apache.hadoop.mapred.Mapper;
org.apache.hadoop.mapred.MapReduceBase;
org.apache.hadoop.mapred.OutputCollector;
org.apache.hadoop.mapred.Reporter;
word.set(wordList.nextToken());
output.collect(word, one);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-28
while (wordList.hasMoreTokens()) {
word.set(wordList.nextToken());
output.collect(word, one);
}
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-29
andvoid
will implement
thekey,
Mapper
public
map(Object
Textinterface.
value, The Mapper
OutputCollector<Text,
IntWritable>
output,
interface
expects four parameters,
which define
the
Reporter reporter) throws IOException {
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-30
Mapper Parameters
The Mappers parameters define the input and output key/value
types
Keys are always WritableComparable
Values are always Writable
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-31
What is Writable?
Hadoop defines its own box classes for strings, integers and so
on
IntWritable for ints
LongWritable for longs
FloatWritable for floats
DoubleWritable for doubles
Text for strings
Etc.
The Writable interface makes serialization quick and easy for
Hadoop
Any values type must implement the Writable interface
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-32
What is WritableComparable?
A WritableComparable is a Writable which is also
Comparable
Two WritableComparables can be compared against each
other to determine their order
Keys must be WritableComparables because they are passed
to the Reducer in sorted order
We will talk more about WritableComparable later
Note that despite their names, all Hadoop box classes implement
both Writable and WritableComparable
For example, IntWritable is actually a
WritableComparable
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-33
IntWritable.
We do
this here
for efficiency, as we
//
Break line into
words
for processing
StringTokenizer wordList = new
will show.
StringTokenizer(value.toString());
while (wordList.hasMoreTokens()) {
word.set(wordList.nextToken());
output.collect(word, one);
}
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-34
Problem: this creates a new object each time around the loop
Your map function will probably be called many thousands or
millions of times for each Map task
Resulting in millions of objects being created
This is very inefficient
Running the garbage collector takes time
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-35
04-36
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-37
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-38
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-39
Within the
mapmap(Object
method, wekey,
split Text
each line
into separate
public
void
value,
OutputCollector<Text,
IntWritable>
output,
words using
Javas
StringTokenizer
class.
Reporter reporter) throws IOException {
// Break line into words for processing
StringTokenizer wordList = new
StringTokenizer(value.toString());
while (wordList.hasMoreTokens()) {
word.set(wordList.nextToken());
output.collect(word, one);
}
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-40
while (wordList.hasMoreTokens()) {
word.set(wordList.nextToken());
output.collect(word, one);
}
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-41
while (wordList.hasMoreTokens()) {
word.set(wordList.nextToken());
output.collect(word, one);
}
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-42
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-43
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-44
java.io.IOException;
java.util.Iterator;
org.apache.hadoop.io.IntWritable;
org.apache.hadoop.io.Text;
org.apache.hadoop.mapred.OutputCollector;
org.apache.hadoop.mapred.MapReduceBase;
org.apache.hadoop.mapred.Reducer;
org.apache.hadoop.mapred.Reporter;
totalWordCount.set(wordCount);
output.collect(key, totalWordCount);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-45
java.io.IOException;
java.util.Iterator;
org.apache.hadoop.io.IntWritable;
org.apache.hadoop.io.Text;
org.apache.hadoop.mapred.OutputCollector;
org.apache.hadoop.mapred.MapReduceBase;
org.apache.hadoop.mapred.Reducer;
org.apache.hadoop.mapred.Reporter;
output.collect(key, totalWordCount);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-46
totalWordCount.set(wordCount);
output.collect(key, totalWordCount);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-47
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-48
int wordCount = 0;
while (values.hasNext()) {
wordCount += values.next().get();
}
totalWordCount.set(wordCount);
output.collect(key, totalWordCount);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-49
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-50
totalWordCount.set(wordCount);
We use the hasNext()
and next()
output.collect(key,
totalWordCount);
methods on
values to step through all the elements in the iterator.
In our example, we are merely adding all the values
together. We use next().get() to retrieve the actual
numeric value.
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-51
totalWordCount.set(wordCount);
output.collect(key, totalWordCount);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-52
totalWordCount.set(wordCount);
output.collect(key, totalWordCount);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-53
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-54
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-55
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-56
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-57
#!/usr/bin/env perl
while (<>) {
chomp;
($k, $v) = split "\t";
print "$v\t$k\n";
}
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-58
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-59
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-60
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-61
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-62
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-63
Conclusion
In this chapter you have learned
How to use the Hadoop API to write a MapReduce program in
Java
How to use the Streaming API to write Mappers and Reducers in
other languages
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
04-64
Chapter 5
The Hadoop Ecosystem
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-1
Course Chapters
Introduction
The Motivation For Hadoop
Hadoop: Basic Contents
Writing a MapReduce Program
The Hadoop Ecosystem
Integrating Hadoop Into The Workflow
Delving Deeper Into The Hadoop API
Common MapReduce Algorithms
An Introduction to Hive and Pig
Debugging MapReduce Programs
Advanced MapReduce Programming
Joining Data Sets in MapReduce Jobs
Graph Manipulation In MapReduce
Conclusion
Appendix: Cloudera Enterprise
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-2
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-3
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-4
Introduction
The term Hadoop is taken to be the combination of HDFS and
MapReduce
There are numerous sub-projects under the Hadoop project at
the Apache Software Foundation (ASF)
Eventually, some of these become fully-fledged top-level projects
There are also some other projects which are directly relevant to
Hadoop, but which are not hosted by the ASF
Typically you will find these on GitHub or another third-party
software repository
All use either HDFS, MapReduce, or both
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-5
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-6
05-7
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-8
05-9
HBase&
Data&layout&
Row1oriented&
Column1oriented&
Transac:ons&
Yes&
Single&row&only&
Query&language&
SQL&
get/put/scan&
Security&
Authen:ca:on/Authoriza:on&
TBD&
Indexes&
On&arbitrary&columns&
Row1key&only&
Max&data&size&
TBs&
PB+&
Read/write&throughput&
limits&
1000s&queries/second&
Millions&of&queries/second&
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-10
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-11
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-12
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-13
What Is Flume?
Flume is a distributed, reliable, available service for efficiently
moving large amounts of data as it is produced
Ideally suited to gathering logs from multiple systems and
inserting them into HDFS as they are generated
Developed in-house by Cloudera, and released as open-source
software
We will discuss Flume in more depth in a later chapter
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-14
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-15
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-16
Fuse-DFS
Fuse-DFS allows mounting HDFS volumes via the Linux FUSE
filesystem
Enables applications which can only write to a standard
filesystem to write to HDFS with no application modification
Caution: Does not imply that HDFS can be used as a generalpurpose filesystem
Still constrained by HDFS limitations
For example, no modifications to existing files
Useful for legacy applications which need to write to HDFS
FUSE:&Filesystem&in&USEr&space&
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-17
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-18
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-19
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-20
05-21
Oozie
Oozie provides a way for developers to define an entire workflow
Comprised of multiple MapReduce jobs
Allows some jobs to run in parallel, others to wait for the output
of a previous job
Workflow definitions are written in XML
We will discuss Oozie in more depth later in the course
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-22
Hue
Hue: The Hadoop User Experience
Graphical front-end to developer and administrator functionality
Uses a Web browser as its front-end
Developed by Cloudera, released as Open Source
Extensible
Publically-available API
Cloudera Enterprise includes extra functionality
Advanced user management
Integration with LDAP, Active Directory
Accounting
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-23
Hue (contd)
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-24
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-25
Conclusion
In this chapter you have learned
What other projects exist around core Hadoop
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
05-26
Chapter 6
Integrating Hadoop Into
The Workflow
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-1
Course Chapters
Introduction
The Motivation For Hadoop
Hadoop: Basic Contents
Writing a MapReduce Program
The Hadoop Ecosystem
Integrating Hadoop Into The Workflow
Delving Deeper Into The Hadoop API
Common MapReduce Algorithms
An Introduction to Hive and Pig
Debugging MapReduce Programs
Advanced MapReduce Programming
Joining Data Sets in MapReduce Jobs
Graph Manipulation In MapReduce
Conclusion
Appendix: Cloudera Enterprise
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-2
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-3
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-4
Introduction
Your data center already has a lot of components
Database servers
Data warehouses
File servers
Backup systems
How does Hadoop fit into this ecosystem?
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-5
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-6
RDBMS Strengths
Relational Database Management Systems (RDBMSs) have many
strengths
Ability to handle complex transactions
Ability to process hundreds or thousands of queries per second
Real-time delivery of results
Simple but powerful query language
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-7
RDBMS Weaknesses
There are some areas where RDBMSs are less ideal
Data schema is determined before data is ingested
Can make ad-hoc data collection difficult
Upper bound on data storage of 100s of Terabytes
Practical upper bound on data in a single query of 10s of
Terabytes
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-8
06-9
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-10
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-11
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-12
Benefits of Hadoop
Processing power scales with data storage
As you add more nodes for storage, you get more processing
power for free
Views do not need prematerialization
Ad-hoc full or partial dataset queries are possible
Total query size can be multiple Petabytes
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-13
Hadoop Tradeoffs
Cannot serve interactive queries
The fastest Hadoop job will still take several seconds to run
Less powerful updates
No transactions
No modification of existing records
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-14
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-15
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-16
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-17
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-18
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-19
06-20
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-21
Tools include:
import
import-all-tables
list-tables
Options include:
--connect
--username
--password
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-22
Sqoop: Example
Example: import a table called employees from a database
called personnel in a MySQL RDBMS
sqoop import --username fred --password derf \
--connect jdbc:mysql://database.example.com/personnel
--table employees
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-23
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-24
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-25
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-26
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-27
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-28
Flume: Basics
Flume is a distributed, reliable, available service for efficiently
moving large amounts of data as it is produced
Ideally suited to gathering logs from multiple systems and
inserting them into HDFS as they are generated
Flume is Open Source
Developed by Cloudera
Flumes design goals:
Reliability
Scalability
Manageability
Extensibility
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-29
Agent&
Agent&&
Agent&
Agent&
encrypt&
MASTER&
Master'communicates'
with'all'Agents,'
specifying'congura$on'
etc.'
Processor&
Processor&
compress&
batch&
Mul$ple'congurable'
levels'of'reliability'
Agents''can'
guarantee'delivery'in'
event'of'failure'
Op$onally'
deployable,'centrally'
administered'
Op$onally'pre=process'
incoming'data:'perform'
transforma$ons,'
suppressions,'metadata'
enrichment'
encrypt&
Writes'to'mul$ple'HDFS'le'
formats'(text,'SequenceFile,'
JSON,'Avro,'others)'
Parallelized'writes'across'many'
collectors''as'much'write'
throughput'as'required'
Collector(s)&
Flexibly'
deploy'
decorators'at'
any'step'to'
improve'
performance,''
reliability'or'
security'
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-30
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-31
06-32
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-33
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-34
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-35
06-36
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-37
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-38
Conclusion
In this chapter you have learned
How Hadoop can be integrating into an existing enterprise
How to load data from an existing RDBMS into HDFS using
Sqoop
How to manage real-time data such as log files using Flume
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
06-39
Chapter 7
Delving Deeper Into
The Hadoop API
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-1
Course Chapters
Introduction
The Motivation For Hadoop
Hadoop: Basic Contents
Writing a MapReduce Program
The Hadoop Ecosystem
Integrating Hadoop Into The Workflow
Delving Deeper Into The Hadoop API
Common MapReduce Algorithms
An Introduction to Hive and Pig
Debugging MapReduce Programs
Advanced MapReduce Programming
Joining Data Sets in MapReduce Jobs
Graph Manipulation In MapReduce
Conclusion
Appendix: Cloudera Enterprise
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-2
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-3
07-4
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-5
Using ToolRunner
Your driver code should extend Configured and implement
Tool
Within the driver code, create a run method
This should create your JobConf object, and then call
JobClient.runJob
In your driver codes main method, use ToolRunner.run to call
the run method
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-6
07-7
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-8
07-9
Recap: Combiners
Recall that a Combiner is like a mini-Reducer
Optional
Runs on the output from a single Mapper
Combiners output is then sent to the Reducer
Combiners often use the same code as the Reducer
Only if the operation is commutative and associative
In this case, input and output data types for the Combiner/
Reducer must be identical
VERY IMPORTANT: Never put code in the Combiner that must be
run as part of your MapReduce job
The Combiner many not be run on the output from some or all of
the Mappers
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-10
Specifying a Combiner
To specify the Combiner class to be used in your MapReduce
code, put the following line in your Driver:
conf.setCombinerClass(YourCombinerClass.class);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-11
07-12
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-13
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-14
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-15
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-16
07-17
07-18
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-19
07-20
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-21
Custom Partitioners
Sometimes you will need to write your own Partitioner
Example: your key is a custom WritableComparable which
contains a pair of values (a, b)
You may decide that all keys with the same value for a need to go
to the same Reducer
The default Partitioner is not sufficient in this case
Write your own Partitioner
In your driver code, configure the job to use the new Partitioner:
conf.setPartitionerClass(MyPartitioner.class);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-22
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-23
07-24
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-25
Counters: An Example
static enum RecType { A, B }
...
void map(KeyType key, ValueType value,
OutputCollector output, Reporter reporter) {
if (isTypeA(value)) {
reporter.incrCounter(RecType.A, 1);
} else {
reporter.incrCounter(RecType.B, 1);
}
// actually process (k, v)
}
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-26
Counters: Caution
Do not rely on a counters value from the Web UI while a job is
running
Due to possible speculative execution, a counters value could
appear larger than the actual final value
Modifications to counters from subsequently killed/failed tasks will
be removed from the final count
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-27
07-28
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-29
The conf object has read in the Hadoop configuration files, and
therefore knows the address of the NameNode etc.
A file in HDFS is represented by a Path object
Path p = new Path("/path/to/my/file");
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-30
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-31
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-32
07-33
07-34
07-35
07-36
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-37
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-38
07-39
Conclusion
In this chapter you have learned
How to specify Combiners
How to use the configure and close methods
How to use SequenceFiles
How to write custom Partitioners
How to use Counters
How to directly access HDFS
How to use the Distributed Cache
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
07-40
Chapter 8
Common MapReduce
Algorithms
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-1
Course Chapters
Introduction
The Motivation For Hadoop
Hadoop: Basic Contents
Writing a MapReduce Program
The Hadoop Ecosystem
Integrating Hadoop Into The Workflow
Delving Deeper Into The Hadoop API
Common MapReduce Algorithms
An Introduction to Hive and Pig
Debugging MapReduce Programs
Advanced MapReduce Programming
Joining Data Sets in MapReduce Jobs
Graph Manipulation In MapReduce
Conclusion
Appendix: Cloudera Enterprise
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-2
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-3
08-4
Introduction
MapReduce jobs tend to be relatively short in terms of lines of
code
It is typical to combine multiple small MapReduce jobs together
in a single workflow
Often using Oozie (see later)
You are likely to find that many of your MapReduce jobs use very
similar code
In this chapter we present some very common MapReduce
algorithms
These algorithms are frequently the basis for more complex
MapReduce jobs
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-5
08-6
Sorting
MapReduce is very well suited to sorting large data sets
Recall: keys are passed to the reducer in sorted order
Assuming the file to be sorted contains lines with a single value:
Mapper is merely the identity function for the value
(k, v) -> (v, _)
Reducer is the identity function
(k, _) -> (k, '')
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-7
Sorting (contd)
Trivial with a single reducer
For multiple reducers, need to choose a partitioning function
such that if k1 < k2, partition(k1) <= partition(k2)
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-8
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-9
Searching
Assume the input is a set of files containing lines of text
Assume the Mapper has been passed the pattern for which to
search as a special parameter
We saw how to pass parameters to your Mapper in the previous
chapter
Algorithm:
Mapper compares the line against the pattern
If the pattern matches, Mapper outputs (line, _)
Or (filename+line, _), or
If the pattern does not match, Mapper outputs nothing
Reducer is the Identity Reducer
Just outputs each intermediate key
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-10
08-11
Indexing
Assume the input is a set of files containing lines of text
Key is the byte offset of the line, value is the line itself
We can retrieve the name of the file using the Reporter object
More details on how to do this later
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-12
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-13
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-14
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-15
08-16
Machine Learning/Classification
Machine learning and classification are complex problems
Much work is currently being done in these subject areas
Here we can only provide a brief overview and pointers to other
resources
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-17
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-18
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-19
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-20
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-21
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-22
08-23
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-24
TF-IDF: Motivation
Merely counting the number of occurrences of a word in a
document is not a good enough measure of its relevance
If the word appears in many other documents, it is probably less
relevance
Some words appear too frequently in all documents to be
relevant
Known as stopwords
TF-IDF considers both the frequency of a word in a given
document and the number of documents which contain the word
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-25
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-26
"N%
idf = log$ '
#n&
N: total number of documents
n: number of documents that contain a term
TF-IDF
TF IDF
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-27
Computing TF-IDF
What we need:
Number of times t appears in a document
Different value for each document
Number of documents that contains t
One value for each term
Total number of documents
One value
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-28
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-29
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-30
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-31
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-32
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-33
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-34
08-35
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-36
Reducer
reduce(pair p, Iterator counts) {
s = 0
foreach c in counts do
s += c
emit(p, s)
}
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-37
08-38
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-39
08-40
Conclusion
In this chapter you have learned
Some typical MapReduce algorithms, including
Sorting
Searching
Indexing
Classification
Term Frequency Inverse Document Frequency
Word Co-Occurrence
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
08-41
Chapter 9
An Introduction to
Hive and Pig
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-1
Course Chapters
Introduction
The Motivation For Hadoop
Hadoop: Basic Contents
Writing a MapReduce Program
The Hadoop Ecosystem
Integrating Hadoop Into The Workflow
Delving Deeper Into The Hadoop API
Common MapReduce Algorithms
An Introduction to Hive and Pig
Debugging MapReduce Programs
Advanced MapReduce Programming
Joining Data Sets in MapReduce Jobs
Graph Manipulation In MapReduce
Conclusion
Appendix: Cloudera Enterprise
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-2
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-3
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-4
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-5
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-6
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-7
Hive: Introduction
Hive was originally developed at Facebook
Provides a very SQL-like language
Can be used by people who know SQL
Under the covers, generates MapReduce jobs that run on the
Hadoop cluster
Enabling Hive requires almost no extra work by the system
administrator
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-8
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-9
Hive Datatypes
Primitive types:
TINYINT
INT
BIGINT
BOOLEAN
DOUBLE
STRING
Type constructors:
ARRAY < primitive-type >
MAP < primitive-type, primitive-type >
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-10
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-11
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-12
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-13
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-14
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-15
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-16
Joining Tables
Joining datasets is a complex operation in standard Java
MapReduce
We will cover this later in the course
In Hive, its easy!
SELECT s.word, s.freq, k.freq FROM
shakespeare s JOIN kjv k ON
(s.word = k.word)
WHERE s.freq >= 5;
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-17
09-18
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-19
Hive Limitations
Not all standard SQL is supported
No correlated subqueries, for example
No support for UPDATE or DELETE
No support for INSERTing single rows
Relatively limited number of built-in functions
No datatypes for date or time
Use the STRING datatype instead
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-20
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-21
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-22
Pig: Introduction
Pig was originally created at Yahoo! to answer a similar need to
Hive
Many developers did not have the Java and/or MapReduce
knowledge required to write standard MapReduce programs
But still needed to query data
Pig is a dataflow language
Language is called PigLatin
Relatively simple syntax
Under the covers, PigLatin scripts are turned into MapReduce
jobs and executed on the cluster
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-23
Pig Installation
Installation of Pig requires no modification to the cluster
The Pig interpreter runs on the client machine
Turns PigLatin into standard Java MapReduce jobs, which are
then submitted to the JobTracker
There is (currently) no shared metadata, so no need for a shared
metastore of any kind
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-24
Pig Concepts
In Pig, a single element of data is an atom
A collection of atoms such as a row, or a partial row is a tuple
Tuples are collected together into bags
Typically, a PigLatin script starts by loading one or more datasets
into bags, and then creates new bags by modifying those it
already has
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-25
Pig Features
Pig supports many features which allow developers to perform
sophisticated data analysis without having to write Java
MapReduce code
Joining datasets
Grouping data
Referring to elements by position rather than name
Useful for datasets with many elements
Loading non-delimited data using a custom SerDe
Creation of user-defined functions, written in Java
And more
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-26
09-27
More PigLatin
To view the structure of a bag:
DESCRIBE bagname;
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-28
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-29
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-30
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-31
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-32
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-33
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-34
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-35
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-36
Conclusion
In this chapter you have learned
What features Hive provides
What features Pig provides
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
09-37
Chapter 10
Debugging MapReduce
Programs
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-1
Course Chapters
Introduction
The Motivation For Hadoop
Hadoop: Basic Contents
Writing a MapReduce Program
The Hadoop Ecosystem
Integrating Hadoop Into The Workflow
Delving Deeper Into The Hadoop API
Common MapReduce Algorithms
An Introduction to Hive and Pig
Debugging MapReduce Programs
Advanced MapReduce Programming
Joining Data Sets in MapReduce Jobs
Graph Manipulation In MapReduce
Conclusion
Appendix: Cloudera Enterprise
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-2
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-3
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-4
Introduction
Debugging MapReduce code is difficult!
Each instance of a Mapper runs as a separate task
Often on a different machine
Difficult to attach a debugger to the process
Difficult to catch edge cases
Very large volumes of data mean that unexpected input is likely
to appear
Code which expects all data to be well-formed is likely to fail
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-5
10-6
Testing Locally
Hadoop can run MapReduce in a single, local process
Does not require any Hadoop daemons to be running
Uses the local filesystem
Known as the LocalJobRunner
This is a very useful way of quickly testing incremental changes
to code
To run in LocalJobRunner mode, add the following lines to your
driver code:
conf.set("mapred.job.tracker", "local");
conf.set("fs.default.name", "file:///");
10-7
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-8
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-9
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-10
10-11
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-12
Introducing MRUnit
A unit-test library for Hadoop, developed by Cloudera
Included in CDH
Provides a framework for sending input to Mappers and
Reducers
and verifying outputs
Framework preserves MapReduce semantics
Tests are compact and inline
Test harness uses mock objects where necessary
Reporter
InputSplit
OutputCollector
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-13
MRUnit Example
class ExampleTest() {
private Example.MyMapper mapper
private Example.MyReducer reducer
private MapReduceDriver driver
@Before
void setUp() {
mapper = new Example.MyMapper()
reducer = new Example.MyReducer()
driver = new MapReduceDriver(mapper, reducer)
}
@Test
void testMapReduce() {
driver.withInput(new Text("k"), new Text("v"))
.withOutput(new Text("foo"), new Text("bar"))
.runTest()
}
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-14
MRUnit Features
Possible to test just the Mapper or just the Reducer
MapDriver
Executes tests for a Mapper
ReduceDriver
Executes tests for a Reducer
MapReduceDriver
Tests a Mapper, performs a shuffle and sort, then tests the
Reducer on the outputs from the Mapper
Mock objects
MockOutputCollector
Delivers results back to the TestDriver
MockReporter
Returns MockInputSplit
MockInputSplit
Dummy InputSplit implementation
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-15
10-16
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-17
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-18
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-19
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-20
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-21
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-22
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-23
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-24
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-25
log4j Configuration
Configuration for log4j is stored in
/etc/hadoop/conf/log4j.properties
Can change global log settings with hadoop.root.log property
Can override log level on a per-class basis:
log4j.logger.org.apache.hadoop.mapred.JobTracker=WARN
log4j.logger.org.apache.hadoop.mapred.FooMapper=DEBUG
Programmatically:
LOGGER.setLevel(Level.WARN);
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-26
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-27
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-28
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-29
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-30
Testing Strategies
When testing in pseudo-distributed mode, ensure that you are
testing with a similar environment to that on the real cluster
Same amount of RAM allocated to the task JVMs
Same version of Hadoop
Same version of Java
Same versions of third-party libraries
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-31
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-32
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-33
Conclusion
In this chapter you have learned
How to debug MapReduce programs using MRUnit
How to write and view logs from your MapReduce programs
Other debugging strategies
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
10-34
Chapter 11
Advanced MapReduce
Programming
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-1
Course Chapters
Introduction
The Motivation For Hadoop
Hadoop: Basic Contents
Writing a MapReduce Program
The Hadoop Ecosystem
Integrating Hadoop Into The Workflow
Delving Deeper Into The Hadoop API
Common MapReduce Algorithms
An Introduction to Hive and Pig
Debugging MapReduce Programs
Advanced MapReduce Programming
Joining Data Sets in MapReduce Jobs
Graph Manipulation In MapReduce
Conclusion
Appendix: Cloudera Enterprise
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-2
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-3
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-4
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-5
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-6
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-7
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-8
Writable
WritableComparable
IntWritable
LongWritable
Text
Defines a de/serialization
protocol. Every data type in
Hadoop is a Writable
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-9
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-10
Inelegant
Problematic
If a or b contained commas
Not always practical
Doesnt easily work for binary objects
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-11
DataInput/DataOutput supports
boolean
byte, char (Unicode, 2 bytes)
double, float, int, long, string
Line until line terminator
unsigned byte, short
UTF string
byte array
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-12
11-13
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-14
WritableComparable
WritableComparable is a sub-interface of Writable
Must implement compareTo, hashCode, equals methods
All keys in MapReduce must be WritableComparable
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-15
11-16
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-17
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-18
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-19
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-20
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-21
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-22
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-23
98
101
12
18
22
55
123
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-24
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-25
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-26
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-27
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-28
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-29
MultiFileInputFormat
Abstract class which manages the use of multiple files in a
single task
You must supply a getRecordReader() implementation
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-30
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-31
What RecordReaders Do
InputSplits are handed to the RecordReaders
Specified by the path, starting position offset, length
RecordReaders must:
Ensure each (key, value) pair is processed
Ensure no (key, value) pair is processed more than once
Handle (key, value) pairs which are split across InputSplits
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-32
Sample InputSplit
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-33
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-34
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-35
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-36
OutputFormat
OutputFormats work much like InputFormat classes
Custom OutputFormats must provide a RecordWriter
implementation
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-37
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-38
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-39
11-40
Oozie Features
Oozie features include:
Run multiple jobs simultaneously
Branch depending on whether a job succeeds or fails
Wait for several upstream jobs to complete before the next job
commences
Run Pig and Hive jobs
Run streaming jobs
Run Sqoop jobs
Etc
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-41
11-42
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-43
Conclusion
In this chapter you have learned
How to create custom Writables and WritableComparables
How to implement a Secondary Sort
How to build custom InputFormats and OutputFormats
How to create pipelines of Hadoop jobs with Oozie
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
11-44
Chapter 12
Joining Data Sets
in MapReduce Jobs
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-1
Course Chapters
Introduction
The Motivation For Hadoop
Hadoop: Basic Contents
Writing a MapReduce Program
The Hadoop Ecosystem
Integrating Hadoop Into The Workflow
Delving Deeper Into The Hadoop API
Common MapReduce Algorithms
An Introduction to Hive and Pig
Debugging MapReduce Programs
Advanced MapReduce Programming
Joining Data Sets in MapReduce Jobs
Graph Manipulation In MapReduce
Conclusion
Appendix: Cloudera Enterprise
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-2
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-3
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-4
Introduction
We frequently need to join data together from two sources as
part of a MapReduce job
Lookup tables
Data from database tables
Etc
There are two fundamental approaches: Map-side joins and
Reduce-side joins
Map-side joins are easier to write, but have potential scaling
issues
We will investigate both types of joins in this chapter
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-5
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-6
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-7
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-8
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-9
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-10
Required output:
EMP: 42, Aaron, loc(13), New York City
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-11
String empName;
int empId;
int locId;
String locationName;
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-12
void map(k, v) {
Record r = parse(v);
emit (r.locId, r);
}
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-13
12-14
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-15
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-16
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-17
}
}
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-18
A Better Mapper
void map(k, v) {
Record r = parse(v);
if (r.type == Typ.emp) {
emit (FK(r.locId), r);
} else {
emit (PK(r.locId), r);
}
}
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-19
A Better Reducer
Record thisLoc;
void reduce(k, values) {
for (Record v in values) {
if (v.type == Typ.loc) {
thisLoc = v;
} else {
v.locationName = thisLoc.locationName;
emit(v);
}
}
}
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-20
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-21
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-22
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-23
Conclusion
In this chapter you have learned
How to join write a Map-side join
How to write a Reduce-side join
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
12-24
Chapter 13
Graph Manipulation
in MapReduce
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-1
Course Chapters
Introduction
The Motivation For Hadoop
Hadoop: Basic Contents
Writing a MapReduce Program
The Hadoop Ecosystem
Integrating Hadoop Into The Workflow
Delving Deeper Into The Hadoop API
Common MapReduce Algorithms
An Introduction to Hive and Pig
Debugging MapReduce Programs
Advanced MapReduce Programming
Joining Data Sets in MapReduce Jobs
Graph Manipulation In MapReduce
Conclusion
Appendix: Cloudera Enterprise
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-2
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-3
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-4
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-5
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-6
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-7
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-8
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-9
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-10
Representing Graphs
Imagine we want to represent this simple graph:
Two approaches:
Adjacency matrices
Adjacency lists
2"
1"
3"
4"
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-11
Adjacency Matrices
Represent the graph as an n x n square matrix
2"
v1 v2 v3 v4
v1 0
v2 1
v3 1
v4 1
1"
3"
4"
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-12
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-13
Adjacency Lists
Take an adjacency matrix and throw away all the zeros
v1 v2 v3 v4
v1 0
v2 1
v3 1
v4 1
v1: v2, v4
v2: v1, v3, v4
v3: v1
v4: v1, v3
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-14
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-15
v1: v2, v4
v2: v1, v3, v4
v3: v1
v4: v1, v3
1: [2] 2, 4
2: [3] 1, 3, 4
3: [1] 1
4: [2] 1, 3
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-16
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-17
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-18
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-19
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-20
13-21
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-22
From%Lin%&%Dyer.%(2010)%Data5Intensive%Text%Processing%with%MapReduce%
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-23
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-24
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-25
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-26
Conclusion
In this chapter you have learned
Best practices for representing graphs in Hadoop
How to implement a single source shortest path algorithm in
MapReduce
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
13-27
Chapter 14
Conclusion
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
14-1
Conclusion
During this course, you have learned:
The core technologies of Hadoop
How HDFS and MapReduce work
What other projects exist in the Hadoop ecosystem
How to develop MapReduce jobs
Algorithms for common MapReduce tasks
How to create large workflows using multiple MapReduce jobs
Best practices for debugging Hadoop jobs
Advanced features of the Hadoop API
How to handle graph manipulation problems with MapReduce
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
14-2
Certification
You can now take the Cloudera Certified Hadoop Developer exam
Your instructor will give you information on how to access the
exam
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
14-3
Appendix A:
Cloudera Enterprise
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
A-1
Cloudera Enterprise
Reduces the risks of running Hadoop in production
Improves consistency, compliance and administrative overhead
Management Suite components:
- Service and Configuration
Manager (SCM)
- Activity Monitor
- Resource Manager
- Authorization Manager
- The Flume User Interface
24x7 Production support for CDH and certified integrations
(Oracle, Netezza, Teradata, Greenplum, Aster Data)
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
A-2
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
A-3
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
A-4
Activity Monitor
Activity Monitor gives an in-depth, comprehensive view of what
is happening on the cluster, in real-time
And what has happened in the past
Compare the performance of similar jobs
Store historical data
Chart metrics on cluster performance
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
A-5
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
A-6
Resource Manager
Resource Manager displays the usage of assets within the
Hadoop cluster
Disk space, processor utilization and more
Easily configure quotas for disk space and number of files
allowed
Display resource usage history for auditing and internal billing
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
A-7
Authorization Manager
Authorization Manager allows you to provision users, and
manage user activity, within the cluster
Configure permissions based on user or group membership
Fine-grained control over permissions
Integrate with Active Directory
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
A-8
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
A-9
Conclusion
Cloudera Enterprise makes it easy to run open source Hadoop in
production
Includes
Cloudera Distribution including Apache Hadoop (CDH)
Cloudera Management Suite (CMS)
Production Support
Cloudera Management Suite enables you to:
Simplify and accelerate Hadoop deployment
Reduce the costs and risks of adopting Hadoop in production
Reliably operate Hadoop in production with repeatable success
Apply SLAs to Hadoop
Increase control over Hadoop cluster provisioning and
management
Copyright 2010-2011 Cloudera. All rights reserved. Not to be reproduced without prior written consent.
A-10