## org.apache.hadoop.mapred.lib
Class FieldSelectionMapReduce<K,V>

    java.lang.Object
      org.apache.hadoop.mapred.lib.FieldSelectionMapReduce<K,V>

All Implemented Interfaces:
  Closeable, JobConfigurable, Mapper<K,V,Text,Text>, Reducer<Text,Text,Text,Text>

    public class FieldSelectionMapReduce<K,V>

extends Object
implements Mapper<K,V,Text,Text>, Reducer<Text,Text,Text,Text>

This class implements a mapper/reducer class that can be used to perform field selections in a manner similar to unix cut. The input data is treated as fields separated by a user specified separator (the default value is "\t"). The user can specify a list of fields that form the map output keys, and a list of fields that form the map output values. If the inputformat is TextInputFormat, the mapper will ignore the key to the map function. and the fields are from the value only. Otherwise, the fields are the union of those from the key and those from the value. The field separator is under attribute "mapred.data.field.separator" The map output field list spec is under attribute "map.output.key.value.fields.spec". The value is expected to be like "keyFieldsSpec:valueFieldsSpec" key/valueFieldsSpec are comma (,) separated field spec: fieldSpec,fieldSpec,fieldSpec ... Each field spec can be a simple number (e.g. 5) specifying a specific field, or a range (like 2-5) to specify a range of fields, or an open range (like 3-) specifying all the fields starting from field 3. The open range field spec applies value fields only. They have no effect on the key fields. Here is an example: "4,3,0,1:6,5,1-3,7-". It specifies to use fields 4,3,0 and 1 for keys, and use fields 6,5,1,2,3,7 and above for values. The reduce output field list spec is under attribute "reduce.output.key.value.fields.spec". The reducer extracts output key/value pairs in a similar manner, except that the key is never ignored.

Field Summary
`static org.apache.commons.logging.Log` `LOG`

Constructor Summary
`FieldSelectionMapReduce()`

Method Summary
`void` `close()`
`void` `configure(JobConf job)` Initializes a new instance from a `JobConf`.
`void` `map(K key, V val, OutputCollector<Text,Text> output, Reporter reporter)` The identify function.
`void` `reduce(Text key, Iterator<Text> values, OutputCollector<Text,Text> output, Reporter reporter)` Reduces values for a given key.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### LOG

    public static final org.apache.commons.logging.Log LOG

Constructor Detail

### FieldSelectionMapReduce

    public FieldSelectionMapReduce()

Method Detail

### map

    public void map(K key,
                    V val,
                    OutputCollector<Text,Text> output,
                    Reporter reporter)
             throws IOException

  The identify function. Input key/value pair is written directly to output.

  Specified by:
    `map` in interface `Mapper<K,V,Text,Text>`
  Parameters:
    `key` - the input key.
    `val` - the input value.
    `output` - collects mapped keys and values.
    `reporter` - facility to report progress.
  Throws:
    `IOException`

### configure

    public void configure(JobConf job)

  Description copied from interface: `JobConfigurable`
  Initializes a new instance from a `JobConf`.

  Specified by:
    `configure` in interface `JobConfigurable`
  Parameters:
    `job` - the configuration

### close

    public void close()
               throws IOException

  Specified by:
    `close` in interface `Closeable`
  Throws:
    `IOException`

### reduce

    public void reduce(Text key,
                       Iterator<Text> values,
                       OutputCollector<Text,Text> output,
                       Reporter reporter)
                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).

  Specified by:
    `reduce` in interface `Reducer<Text,Text,Text,Text>`
  Parameters:
    `key` - the key.
    `values` - the list of values to reduce.
    `output` - to collect keys and combined values.
    `reporter` - facility to report progress.
  Throws:
    `IOException`

Copyright © 2009 The Apache Software Foundation