org.apache.hadoop.contrib.utils.join
Class DataJoinMapperBase

java.lang.Object
  extended by org.apache.hadoop.contrib.utils.join.JobBase
      extended by org.apache.hadoop.contrib.utils.join.DataJoinMapperBase
All Implemented Interfaces:
Closeable, JobConfigurable, Mapper, Reducer

public abstract class DataJoinMapperBase
extends JobBase

This abstract class serves as the base class for the mapper class of a data join job. This class expects its subclasses to implement methods for the following functionalities: 1. Compute the source tag of input values 2. Compute the map output value object 3. Compute the map output key object The source tag will be used by the reducer to determine from which source (which table in SQL terminology) a value comes. Computing the map output value object amounts to performing projecting/filtering work in a SQL statement (through the select/where clauses). Computing the map output key amounts to choosing the join key. This class provides the appropriate plugin points for the user defined subclasses to implement the appropriate logic.


Field Summary
protected  String inputFile
           
protected  Text inputTag
           
protected  JobConf job
           
protected  Reporter reporter
           
 
Fields inherited from class org.apache.hadoop.contrib.utils.join.JobBase
LOG
 
Constructor Summary
DataJoinMapperBase()
           
 
Method Summary
 void close()
           
 void configure(JobConf job)
          Initializes a new instance from a JobConf.
protected abstract  Text generateGroupKey(TaggedMapOutput aRecord)
          Generate a map output key.
protected abstract  Text generateInputTag(String inputFile)
          Determine the source tag based on the input file name.
protected abstract  TaggedMapOutput generateTaggedMapOutput(Object value)
          Generate a tagged map output value.
 void map(Object key, Object value, OutputCollector output, Reporter reporter)
          Maps a single input key/value pair into an intermediate key/value pair.
 void reduce(Object arg0, Iterator arg1, OutputCollector arg2, Reporter arg3)
          Reduces values for a given key.
 
Methods inherited from class org.apache.hadoop.contrib.utils.join.JobBase
addDoubleValue, addLongValue, getDoubleValue, getLongValue, getReport, report, setDoubleValue, setLongValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inputFile

protected String inputFile

job

protected JobConf job

inputTag

protected Text inputTag

reporter

protected Reporter reporter
Constructor Detail

DataJoinMapperBase

public DataJoinMapperBase()
Method Detail

configure

public void configure(JobConf job)
Description copied from class: JobBase
Initializes a new instance from a JobConf.

Specified by:
configure in interface JobConfigurable
Overrides:
configure in class JobBase
Parameters:
job - the configuration

generateInputTag

protected abstract Text generateInputTag(String inputFile)
Determine the source tag based on the input file name.

Parameters:
inputFile -
Returns:
the source tag computed from the given file name.

generateTaggedMapOutput

protected abstract TaggedMapOutput generateTaggedMapOutput(Object value)
Generate a tagged map output value. The user code can also perform projection/filtering. If it decides to discard the input record when certain conditions are met,it can simply return a null.

Parameters:
value -
Returns:
an object of TaggedMapOutput computed from the given value.

generateGroupKey

protected abstract Text generateGroupKey(TaggedMapOutput aRecord)
Generate a map output key. The user code can compute the key programmatically, not just selecting the values of some fields. In this sense, it is more general than the joining capabilities of SQL.

Parameters:
aRecord -
Returns:
the group key for the given record

map

public void map(Object key,
                Object value,
                OutputCollector output,
                Reporter reporter)
         throws IOException
Description copied from interface: Mapper
Maps a single input key/value pair into an intermediate key/value pair.

Output pairs need not be of the same types as input pairs. A given input pair may map to zero or many output pairs. Output pairs are collected with calls to OutputCollector.collect(Object,Object).

Applications can use the Reporter provided to report progress or just indicate that they are alive. In scenarios where the application takes an insignificant amount of time to process individual key/value pairs, this is crucial since the framework might assume that the task has timed-out and kill that task. The other way of avoiding this is to set mapred.task.timeout to a high-enough value (or even zero for no time-outs).

Parameters:
key - the input key.
value - the input value.
output - collects mapped keys and values.
reporter - facility to report progress.
Throws:
IOException

close

public void close()
           throws IOException
Throws:
IOException

reduce

public void reduce(Object arg0,
                   Iterator arg1,
                   OutputCollector arg2,
                   Reporter arg3)
            throws IOException
Description copied from interface: Reducer
Reduces values for a given key.

The framework calls this method for each <key, (list of values)> pair in the grouped inputs. Output values must be of the same type as input values. Input keys must not be altered. The framework will reuse the key and value objects that are passed into the reduce, therefore the application should clone the objects they want to keep a copy of. In many cases, all values are combined into zero or one value.

Output pairs are collected with calls to OutputCollector.collect(Object,Object).

Applications can use the Reporter provided to report progress or just indicate that they are alive. In scenarios where the application takes an insignificant amount of time to process individual key/value pairs, this is crucial since the framework might assume that the task has timed-out and kill that task. The other way of avoiding this is to set mapred.task.timeout to a high-enough value (or even zero for no time-outs).

Parameters:
arg0 - the key.
arg1 - the list of values to reduce.
arg2 - to collect keys and combined values.
arg3 - facility to report progress.
Throws:
IOException


Copyright © 2009 The Apache Software Foundation