Book Image

Hadoop Real-World Solutions Cookbook

By : Jonathan R. Owens, Jon Lentz, Brian Femiano
Book Image

Hadoop Real-World Solutions Cookbook

By: Jonathan R. Owens, Jon Lentz, Brian Femiano

Overview of this book

<p>Helping developers become more comfortable and proficient with solving problems in the Hadoop space. People will become more familiar with a wide variety of Hadoop related tools and best practices for implementation.</p> <p>Hadoop Real-World Solutions Cookbook will teach readers how to build solutions using tools such as Apache Hive, Pig, MapReduce, Mahout, Giraph, HDFS, Accumulo, Redis, and Ganglia.</p> <p>Hadoop Real-World Solutions Cookbook provides in depth explanations and code examples. Each chapter contains a set of recipes that pose, then solve, technical challenges, and can be completed in any order. A recipe breaks a single problem down into discrete steps that are easy to follow. The book covers (un)loading to and from HDFS, graph analytics with Giraph, batch data analysis using Hive, Pig, and MapReduce, machine learning approaches with Mahout, debugging and troubleshooting MapReduce, and columnar storage and retrieval of structured data using Apache Accumulo.<br /><br />Hadoop Real-World Solutions Cookbook will give readers the examples they need to apply Hadoop technology to their own problems.</p>
Table of Contents (17 chapters)
Hadoop Real-World Solutions Cookbook
Credits
About the Authors
About the Reviewers
www.packtpub.com
Preface
Index

Creating custom Hadoop Writable and InputFormat to read geographical event data


When reading input, or writing output from a MapReduce application, it is sometimes easier to work with data using an abstract class instead of the primitive Hadoop Writable classes (for example, Text and IntWritable). This recipe demonstrates how to create a custom Hadoop Writable and InputFormat that can be used by MapReduce applications.

Getting ready

You will need to download the Nigeria_ACLE D_cleaned.tsv dataset from http://www.packtpub.com/support and place the file into HDFS.

How to do it...

Follow these steps to create custom InputFormat and Writable classes:

  1. First we will define two custom WritableComparable classes. These classes represent the key-value pairs that are passed to the mapper, much as how TextInputFormat passes LongWritable and Text to the mapper.

    Write the key class:

    public class GeoKey implements WritableComparable {
        private Text location;
        private FloatWritable latitude;
        private...