Apache Crunch: Laying the pipelines for the Hadoop refinery

Apache Crunch recently graduated from an incubator to an ASF top level project. Let’s take a better look at this Java library which aims to make writing, testing and running MapReduce pipelines easy.

Real world problems require a chain of Map, Shuffle, Reduce, Combine phases sequenced in parallel or one after the another. This chain of MapReduce phases for processing can be simply termed as a MapReduce pipeline. To coordinate this pipeline as well as provide data and implementation abstraction, Apache Crunch provides a library for Hadoop programmers. Hadoop, as we know, has often been compared to be a Data refinery and it makes sort of literal analogous extension for Crunch to fit in the role of pipeline for the Hadoop data refinery.

At the core of Apache Crunch is a data model which consists of classes like PCollection<T> and PTable<K,V> representing distributed, immutable collection of objects. Further, it has a defined set of operators which support primitive operations for parallel processing, grouping, sorting etc.
(hover over elements below to view description)

Data ModelOperators
Pipeline
DoFn
MRPipeline
CombineFn
MemPipeline
FilterFn
PCollection
Joins
PTable
Cartesian
PGroupTable
Sort
Source
Secondary Sort
Target
PObject
Emitter
BloomFilters
PType


For instance, to implement the common Word Count example, an Apache Crunch program would have the following steps:

  1. Create a Pipeline object
  2. Read input (e.g. text file) into a PCollection
  3. Execute various functions on input data
    e.g.
     
    PTable<String, Long> counts =
      lines.parallelDo(extractWord,
        Writables.strings())
            .count();
    Or
    PCollection<String> words = lines.parallelDo(new DoFn<String, String>() {
    public void process(String line, Emitter<String> emitter) {
            for (String word : line.split("\\s+")) {
              emitter.emit(word);
            }
          }
        }, Writables.strings());

     PTable<String, Long> counts = words.count();

  1. Persist the output collection and execute the pipeline


Beyond Pig and Hive, there are a couple of competing tools which have emerged in this space including Cascading, Scalding, Cascalog, Scoobi, Spark.  Apache Crunch, however like its parent FlumeJava, uses a multiple serializable type(MST) model instead of single serializable type(SST) model. MST is claimed by Crunch team to provide compile time verification, easy writing of user defined functions and support jobs using complex data types. Further, its is claimed to be a “better fit for data sets that do not naturally fit into the Tuple model, such as images, time series, audio files and seismograms”.

Crunch's MST serialization model currently has two different implementations, one based on Writables and the other based on Avro records. It has been acknowledged based on independent benchmarking that Avro implementation is much faster than Writables and should be preferred implementation for Crunch to gain performance advantage. Now that Crunch has matured out as top level project, we hope to see more committers and contributors beyond the currently pro-active pool. There is still some more usability journey for the product to cover like better documentation, easy tutorials, and manageable code. However, all these would be routine release activities as it registers its presence as part of commercial distributions as well. Meanwhile, welcome the new graduate. Cheers.