Chicago Crime (2013) Analysis Using Pig and Visualization Using R
Chicago Crime (2013) Analysis Using Pig and Visualization Using R
Technology, Jaipur
PROJECT REPORT
ON
Project Report for the Training Completion and Project Made During Training
Period
Submitted By:
2017-18
Index
2) Abstract 4
3) Chapter1
4) Chapter 2-
5) Chapter 3-
3.1 MapReduce 13
3.2 Programming Model 14
3.3 Map 15
3.4 Reduce 16
3.5 HDFS 17
3.6 HDFS Concepts 19
3.7Hadoop File System 22
6) Chapter 4-
7) Chapter 5-
8)Chapter 6-
9) Chapter 7-
Page 2
Hadoop Framework
10) Chapter 8-
Conclusion 54-55
11) References-
Reference 56-57
Page 3
Hadoop Framework
ACKNOWLEDGEMENT
I have taken efforts in this project. However, it would not have been possible without the kind
support and help of many individuals and organizations. I would like to extend my sincere
thanks to all of them.
I am highly indebted to CEG for their guidance and constant supervision as well as for
providing necessary information regarding the project & also for their support in completing
the project.
I would like to express my gratitude towards my parents & member of CEG for their kind co-
operation and encouragement which help me in completion of this project.
I would like to express my special gratitude and thanks to industry persons for giving me
such attention and time.
My thanks and appreciations also go to my colleague in developing the project and people
who have willingly helped me out with their abilities.
Page 4
Hadoop Framework
ABSTRACT
Page 5
Hadoop Framework
CHAPTER 1:
INTRODUCTION TO
HADOOP
Page 6
Hadoop Framework
Chapter 1:
Introduction to HADOOP
Today, were surrounded by data. People upload videos, take pictures on their cell phones,
text friends, update their Facebook status, leave comments around the web, click on ads, and
so forth. Machines, too, are generating and keeping more and more data.
The exponential growth of data first presented challenges to cutting-edge businesses such
as Google, Yahoo, Amazon, and Microsoft. They needed to go through terabytes and
petabytes of data to figure out which websites were popular, what books were in demand, and
what kinds of ads appealed to people. Existing tools were becoming inadequate to process
such large data sets. Google was the first to publicize MapReducea system they had used to
scale their data processing needs.
This system aroused a lot of interest because many other businesses were facing similar
scaling challenges, and it wasnt feasible for everyone to reinvent their own proprietary tool.
Doug Cutting saw an opportunity and led the charge to develop an open source version of this
MapReduce system called Hadoop. Soon after, Yahoo and others rallied around to support
this effort. Today, Hadoop is a core part of the computing infrastructure for many web
companies, such as Yahoo, Facebook, LinkedIn, and Twitter.
Hadoop is an open source framework for writing and running distributed applications that
process large amounts of data. Distributed computing is a wide and varied field, but the key
distinctions of Hadoop are that it is
AccessibleHadoop runs on large clusters of commodity machines or on cloud
computing services such as Amazons Elastic Compute Cloud (EC2 ).
RobustBecause it is intended to run on commodity hardware, Hadoop is
architected with the assumption of frequent hardware malfunctions. It can gracefully handle
most such failures.
ScalableHadoop scales linearly to handle larger data by adding more nodes to the
cluster.
Page 7
Hadoop Framework
Hadoops accessibility and simplicity give it an edge over writing and running large
distributed programs. Even college students can quickly and cheaply create their own Hadoop
cluster. On the other hand, its robustness and scalability make it suitable for even the most
demanding jobs at Yahoo and Facebook.
Page 8
Hadoop Framework
CHAPTER 2:
HISTORY OF HADOOP
Page 9
Hadoop Framework
Chapter 2:
History of HADOOP
Page 10
Hadoop Framework
Hadoop was created by Doug Cutting, the creator of Apache Lucene, the widely used text
search library. Hadoop has its origins in Apache Nutch, an open source web search engine,
itself a part of the Lucene project.
Page 11
Hadoop Framework
The name my kid gave a stuffed yellow elephant. Short, relatively easy to spell and
pronounce, meaningless, and not used elsewhere: those are my naming criteria. Kids are
good at generating such. Googol is a kids term.
Subprojects and contrib modules in Hadoop also tend to have names that are unrelated
to their function, often with an elephant or other animal theme (Pig, for example). Smaller
components are given more descriptive (and therefore more mundane) names. This is a good
principle, as it means you can generally work out what something does from its name. For
example, the jobtracker keeps track of MapReduce jobs.
Building a web search engine from scratch was an ambitious goal, for not only is the
software required to crawl and index websites complex to write, but it is also a challenge to
run without a dedicated operations team, since there are so many moving parts. Its expensive
too: Mike Cafarella and Doug Cutting estimated a system supporting a 1- billion-page index
would cost around half a million dollars in hardware, with a monthly running cost of $30,000.
Nevertheless, they believed it was a worthy goal, as it would open up and ultimately
democratize search engine algorithms. Nutch was started in 2002, and a working crawler and
search system quickly emerged.
However, they realized that their architecture wouldnt scale to the billions of pages on the
Web. Help was at hand with the publication of a paper in 2003 that described the architecture
of Googles distributed filesystem, called GFS, which was being used in production at
Google.# GFS, or something like it, would solve their storage needs for the very large files
generated as a part of the web crawl and indexing process. In particular, GFS would free up
time being spent on administrative tasks such as managing storage nodes. In 2004, they set
about writing an open source implementation, the Nutch Distributed Filesystem (NDFS).
In 2004, Google published the paper that introduced MapReduce to the world. Early in
2005, the Nutch developers had a working MapReduce implementation in Nutch, and by the
middle of that year all the major Nutch algorithms had been ported to run using MapReduce
and NDFS. NDFS and the MapReduce implementation in Nutch were applicable beyond the
realm of search, and in February 2006 they moved out of Nutch to form an independent
subproject of Lucene called Hadoop. At around the same time, Doug Cutting joined Yahoo!,
which provided a dedicated team and the resources to turn Hadoop into a system that ran at
web scale (see sidebar). This was demonstrated in February 2008 when Yahoo! announced
that its production search index was being generated by a 10,000-core Hadoop cluster.
Page 12
Hadoop Framework
In January 2008, Hadoop was made its own top-level project at Apache, confirming its
success and its diverse, active community. By this timem Hadoop was being used by many
other companies besides Yahoo!, such as Last.fm, Facebook, and the New York Times.
Page 13
Hadoop Framework
CHAPTER 3:
KEY TECHNOLOGY
Page 14
Hadoop Framework
Chapter 3:
Key Technology
The key technology for Hadoop is the MapReduce programming model and Hadoop
Distributed File System. The operation on large data is not possible in serial programming
paradigm. MapReduce do task parallel to accomplish work in less time which is the main aim
of this technology. MapReduce require special file system. In the real scenario , the data
which are in terms on perabyte. To store and maintain this much data on distributed
commodity hardware, Hadoop Distributed File System is invented. It is basically inspired by
Google File System.
3.1 MapReduce
MapReduce is a framework for processing highly distributable problems across huge
datasets using a large number of computers (nodes), collectively referred to as a cluster (if all
nodes use the same hardware) or a grid (if the nodes use different hardware). Computational
processing can occur on data stored either in a filesystem (unstructured) or in a database
(structured).
"Map" step: The master node takes the input, partitions it up into smaller sub-problems, and
distributes them to worker nodes. A worker node may do this again in turn, leading to a multi-
Page 15
Hadoop Framework
level tree structure. The worker node processes the smaller problem, and passes the answer
back to its master node.
"Reduce" step: The master node then collects the answers to all the sub-problems and
combines them in some way to form the output the answer to the problem it was originally
trying to solve.
MapReduce allows for distributed processing of the map and reduction operations.
Provided each mapping operation is independent of the others, all maps can be performed in
parallel though in practice it is limited by the number of independent data sources and/or
the number of CPUs near each source. Similarly, a set of 'reducers' can perform the reduction
phase - provided all outputs of the map operation that share the same key are presented to the
same reducer at the same time. While this process can often appear inefficient compared to
algorithms that are more sequential, MapReduce can be applied to significantly larger
datasets than "commodity" servers can handle a large server farm can use MapReduce to
sort a petabyte of data in only a few hours. The parallelism also offers some possibility of
recovering from partial failure of servers or storage during the operation: if one mapper or
reducer fails, the work can be rescheduled assuming the input data is still available.
MapReduce is a programming model and an associated implementation for processing
and generating largedata sets. Users specify a map function that processes a key/value pair to
generate a set of intermediate key/value pairs, and a reduce function that merges all
intermediate values associated with the same intermediate key. Many real world tasks are
expressible in this model.
The computation takes a set of input key/value pairs, and produces a set of output
key/value pairs. The user of the MapReduce library expresses the computation as two
functions: Map and Reduce. Map, written by the user, takes an input pair and produces a set
of intermediate key/value pairs. The MapReduce library groups together all intermediate
values associatedwith the same intermediate key I and passes them to the Reduce function.
The Reduce function, also written by the user, accepts an intermediate key I and a set of
values for that key. It merges together these values to form a possibly smaller set of values.
Typically just zero or one output value is produced per Reduce invocation. The intermediate
Page 16
Hadoop Framework
values are supplied to the user's reduce function via an iterator. This allows us to handle lists
of values that are too large to fit in memory.
3.3 MAP
map (in_key, in_value) -> (out_key, intermediate_value) list
Page 17
Hadoop Framework
3.4 REDUCE
Page 18
Hadoop Framework
A Map-Reduce job usually splits the input data-set into independent chunks which are
processed by the map tasks in a completely parallel manner. The framework sorts the outputs
of the maps, which are then input to the reduce tasks. Typically both the input and the output
of the job are stored in a file-system. The framework takes care of scheduling tasks,
monitoring them and re-executes the failed tasks.
A MapReducejob is a unit of work that the client wants to be performed: it consists of the
input data, the MapReduce program, and configuration information. Hadoop runs the job by
dividing it into tasks, of which there are two types: map tasks and reduce tasks. There are two
types of nodes that control the job execution process: a jobtrackerand a number of
tasktrackers. The jobtracker coordinates all the jobs run on the system by scheduling tasks to
run on tasktrackers.
Figure 4: HadoopMapReduce
Page 19
Hadoop Framework
HDFS was originally built as infrastructure for the Apache Nutch web search engine project.
HDFS is now an Apache Hadoop subproject.
Page 20
Hadoop Framework
deployed on a wide range of machines. A typical deployment has a dedicated machine that
runs only the NameNode software. Each of the other machines in the cluster runs one
instance of the DataNode software. The architecture does not preclude running multiple
DataNodes on the same machine but in a real deployment that is rarely the case.
The existence of a single NameNode in a cluster greatly simplifies the architecture of the
system. The NameNode is the arbitrator and repository for all HDFS metadata. The system is
designed in such a way that user data never flows through the NameNode.
Filesystems that manage the storage across a network of machines are called
distributed filesystems. Since they are network-based, all the complications of network
programming kick in, thus making distributed filesystems more complex than regular disk
filesystems. For example, one of the biggest challenges is making the filesystem tolerate node
failure without suffering data loss. Hadoop comes with a distributed filesystem called HDFS,
which stands for HadoopDistributed Filesystem.
HDFS, the Hadoop Distributed File System, is a distributed file system designed to
hold very large amounts of data (terabytes or even petabytes), and provide high-
throughput access to this information. Files are stored in a redundant fashion across
multiple machines to ensure their durability to failure and high availability to very parallel
applications.
a) Blocks
A disk has a block size, which is the minimum amount of data that it can read or write.
Filesystems for a single disk build on this by dealing with data in blocks, which are an
integral multiple of the disk block size. Filesystem blocks are typically a few kilobytes in
size, while disk blocks are normally 512 bytes. This is generally transparent to the filesystem
user who is simply reading or writing a fileof whatever length. However, there are tools to
do with filesystem maintenance, such as dfand fsck, that operate on the filesystem block
Page 21
Hadoop Framework
level. HDFS too has the concept of a block, but it is a much larger unit64 MB by default.
Like in a filesystem for a single disk, files in HDFS are broken into block-sized chunks,
which are stored as independent units. Unlike a filesystem for a single disk, a file in HDFS
that is smaller than a single block does not occupy a full blocks worth of underlying storage.
When unqualified, the term block in this book refers to a block in HDFS.
Page 22
Hadoop Framework
ersistently, since this information is reconstructed from datanodes when the system starts. A
client accesses the filesystem on behalf of the user by communicating with the namenode and
datanodes.
The client presents a POSIX-like filesystem interface, so the user code does not need to know
about the namenode and datanode to function. Datanodes are the work horses of the
filesystem. They store and retrieve blocks when they are told to (by clients or the namenode),
Page 23
Hadoop Framework
and they report back to the namenode periodically with lists of blocks that they are storing.
Without the namenode, the filesystem cannot be used. In fact, if the machine running the
namenode were obliterated, all the files on the filesystem would be lost since there would be
no way of knowing how to reconstruct the files from the blocks on the datanodes. For this
reason, it is important to make the namenode resilient to failure.
d) Data Replication
HDFS is designed to reliably store very large files across machines in a large cluster. It stores
each file as a sequence of blocks; all blocks in a file except the last block are the same size.
The blocks of a file are replicated for fault tolerance. The block size and replication factor are
configurable per file. An application can specify the number of replicas of a file. The
replication factor can be specified at file creation time and can be changed later.
Data replication
Page 24
Hadoop Framework
Hadoop has an abstract notion of filesystem, of which HDFS is just one implementation. The
Java abstract class org.apache.hadoop.fs.FileSystem represents a filesystem in Hadoop, and
there are several concrete implementations, which are described in following table.
A filesystem for a locally
connected disk with client-side
Local file checksums.
fs.LocalFileSystem Use RawLocalFileSystem for a
local filesystem with no
checksums.
Hadoops distributed filesystem.
HDFS is designed to work
HDFS hdfs hdfs.DistributedFileSystem efficiently in conjunction with
Map-Reduce.
A filesystem layered on another
filesystem for archiving files.
HAR har Fs.HarFileSystem Hadoop
Archives are typically used for
archiving files in HDFS to reduce
the namenodes memory usage.
CloudStore (formerly
Kosmosfilesystem)is a distributed
KFS(C Kfs fs.kfs.KosmosFileSystem filesystem like HDFS or Googles
loud GFS, written in C++.
Store)
A filesystem backed by an FTP
FTP ftp fs.ftp.FtpFileSystem server.
Table: 8.2 Various HadoopFilesystems
Page 25
Hadoop Framework
HDFS stores small files inefficiently, since each file is stored in a block, and block
metadata is held in memory by the namenode. Thus, a large number of small files can eat up
a lot of memory on the namenode. (Note, however, that small files do not take up any more
disk space than is required to store the raw contents of the file. For example, a 1 MB file
stored with a block size of 128 MB uses 1 MB of disk space, not 128 MB.) Hadoop Archives,
or HAR files, are a file archiving facility that packs files into HDFS blocks more efficiently,
thereby reducing namenode memory usage while still allowing transparent access to files. In
particular, Hadoop Archives can be used as input to MapReduce.
CHAPTER 4
Page 26
Hadoop Framework
HADOOP
ECOSYSTEMS
Page 27
Hadoop Framework
4.1 Avro
4. Simple integration with dynamic languages. Code generation is not required to read
or write data files nor to use or implement RPC protocols. Code generation as an
optional optimization, only worth implementing for statically typed languages.
4.2 Chukwa
Chukwa is a Hadoop subproject devoted to large-scale log collection and analysis. Chukwa
is built on top of the Hadoop distributed filesystem (HDFS) and MapReduce framework and
inherits Hadoops scalability and robustness. Chukwa also includes a exible and powerful
toolkit for displaying monitoring and analyzing results, in order to make the best use of this
collected data.
4.3 HBase
Just as Google's Bigtable leverages the distributed data storage provided by the Google File
System, HBase provides Bigtable-like capabilities on top of Hadoop Core.
4.4 Hive
Page 28
Hadoop Framework
Hive is a data warehouse system for Hadoop that facilitates easy data summarization, ad-hoc
queries, and the analysis of large datasets stored in Hadoop compatible file systems. Hive
provides a mechanism to project structure onto this data and query the data using a SQL-like
language called HiveQL. At the same time this language also allows traditional map/reduce
programmers to plug in their custom mappers and reducers when it is inconvenient or
inefficient to express this logic in HiveQL.
4.5 Pig
Apache Pig is a platform for analyzing large data sets that consists of a high-level language
for expressing data analysis programs, coupled with infrastructure for evaluating these
programs. The salient property of Pig programs is that their structure is amenable to
substantial parallelization, which in turns enables them to handle very large data sets.
4.6 ZooKeeper
Page 29
Hadoop Framework
4.7 Oozie
Page 30
Hadoop Framework
CHAPTER 5
APPLICATIONS OF
HADOOP
Page 31
Hadoop Framework
Chapter 4
Applications of Hadoop
4.1.
Amazon S3 (Simple Storage Service) is a data storage service. You are billed monthly for
storage and data transfer. Transfer between S3 and AmazonEC2 is free. This makes use of S3
attractive for Hadoop users who run clusters on EC2.
4.2.
Facebooks engineering team has posted some details on the tools its using to analyze the
huge data sets it collects. One of the main tools it uses is Hadoop that makes it easier to
analyze vast amounts of data.
Some interesting tidbits from the post:
Facebook has multiple Hadoop clusters deployed now - with the biggest having about 2500
cpu cores and 1 PetaByte of disk space. They are loading over 250 gigabytes of compressed
data (over 2 terabytes uncompressed) into the Hadoop file system every day and have
hundreds of jobs running each day against these data sets. The list of projects that are using
this infrastructure has proliferated - from those generating mundane statistics about site
usage, to others being used to fight spam and determine application quality.
Page 32
Hadoop Framework
Over time, we have added classic data warehouse features like partitioning,
sampling and indexing to this environment. This in-house data warehousing
layer over Hadoop is called Hive.
4.3 .
Yahoo! recently launched the world's largest Apache Hadoop production application.
The Yahoo! Search Webmap is a Hadoop application that runs on a more than 10,000
core Linux cluster and produces data that is now used in every Yahoo! Web search
query.
The Webmap build starts with every Web page crawled by Yahoo! and produces a
database of all known Web pages and sites on the internet and a vast array of data
about every page and site. This derived data feeds the Machine Learned Ranking
algorithms at the heart of Yahoo! Search.
Some Webmap size data:Number of links between pages in the index: roughly 1
trillion links
Page 33
Hadoop Framework
CHAPTER 6
PROJECT
MODULES
Page 34
Hadoop Framework
Page 35
Hadoop Framework
Pig Script:
Page 36
Hadoop Framework
Pig Script:
Page 37
Hadoop Framework
Pig Script:
Page 38
Hadoop Framework
Pig Script:
Page 39
Hadoop Framework
Problem Statement 5: A look at the date and time when the highest
number of incidents were reported.
Pig Script:
Page 40
Hadoop Framework
Pig Script:
His
Page 41
Hadoop Framework
Pig Script:
Page 42
Hadoop Framework
Page 43
Hadoop Framework
Problem Statement 8: A look at the date and time when the highest
number of arrests took place.
Pig Script:
Page 44
Hadoop Framework
CHAPTER 7
VISUALIZATION
USING
R PROGRAMMING
LANGUAGE
Page 45
Hadoop Framework
INTRODUCTION TO R:
The core of R is an interpreted computer language which allows branching and looping as
well as modular programming using functions. R allows integration with the procedures
written in the C, C++, .Net, Python or FORTRAN languages for efficiency.
R is freely available under the GNU General Public License, and pre-compiled binary
versions are provided for various operating systems like Linux, Windows and Mac.
R is free software distributed under a GNU-style copy left, and an official part of the GNU
project called GNU S.
Evolution of R
R was initially written by Ross Ihaka and Robert Gentleman at the Department of
Statistics of the University of Auckland in Auckland, New Zealand. R made its first
appearance in 1993.
A large group of individuals has contributed to R by sending code and bug reports.
Since mid-1997 there has been a core group (the "R Core Team") who can modify the R source
code archive.
Page 46
Hadoop Framework
FEATURES OF R
As stated earlier, R is a programming language and software environment for statistical
analysis, graphics representation and reporting. The following are the important features of
R
R provides graphical facilities for data analysis and display either directly at
the computer or printing at the papers.
As a conclusion, R is worlds most widely used statistics programming language. It's the # 1
choice of data scientists and supported by a vibrant and talented community of contributors.
R is taught in universities and deployed in mission critical business applications.
Page 47
Hadoop Framework
Page 48
Hadoop Framework
Page 49
Hadoop Framework
Page 50
Hadoop Framework
Page 51
Hadoop Framework
Page 52
Hadoop Framework
Page 53
Hadoop Framework
Page 54
Hadoop Framework
Page 55
Hadoop Framework
Page 56
Hadoop Framework
Page 57
Hadoop Framework
CHAPTER 8:
CONCLUSION
Page 58
Hadoop Framework
Chapter 5
CONCLUSION
By the above description we can understand the need of Big Data in future, so
Hadoop can be the best of maintenance and efficient implementation of large
data.
This technology has bright future scope because day by day need of data
would increase and security issues also the major point. In now a day many
Multinational organizations are prefer Hadoop over RDBMS.
So major companies like Facebook amazon, yahoo, LinkedIn etc. are adapting
Hadoop and in future there can be many names in the list.
Hence Hadoop Technology is the best appropriate approach for handling the
large data in smart way and its future is bright
Future work:
1. This analysis can be further carried out on Fully Distributed cluster mode that is hadoop
Page 59
Hadoop Framework
REFERENCES:
Page 60
Hadoop Framework
References:
http://www.cloudera.com/hadoop-training-thinking-at-scale
http://developer.yahoo.com/hadoop/tutorial/module1.html
http://hadoop.apache.org/core/docs/current/api/
http://hadoop.apache.org/core/version_control.html
http://wikipidea.in/apachehadoop.com
Page 61