Book Image

Hadoop MapReduce v2 Cookbook - Second Edition: RAW

Book Image

Hadoop MapReduce v2 Cookbook - Second Edition: RAW

Overview of this book

Table of Contents (19 chapters)
Hadoop MapReduce v2 Cookbook Second Edition
Credits
About the Author
Acknowledgments
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing a custom Hadoop key type


The instances of Hadoop MapReduce key types should have the ability to compare against each other for sorting purposes. In order to be used as a key type in a MapReduce computation, a Hadoop Writable data type should implement the org.apache.hadoop.io.WritableComparable<T> interface. The WritableComparable interface extends the org.apache.hadoop.io.Writable interface and adds the compareTo() method to perform the comparisons.

In this recipe, we modify the LogWritable data type of the Implementing a custom Hadoop Writable data type recipe to implement the WritableComparable interface.

How to do it...

The following are the steps to implement a custom Hadoop WritableComparable data type for the HTTP server log entries, which uses the request hostname and timestamp for comparison.

  1. Modify the LogWritable class to implement the org.apache.hadoop.io.WritableComparable interface:

    public class LogWritable implements
      WritableComparable<LogWritable> {...