Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.75 KB | None | 0 0
  1. package test.invertedIndex
  2.  
  3. import java.io.IOException;
  4. import java.util.Iterator;
  5. import org.apache.hadoop.io.Text;
  6. import org.apache.hadoop.mapred.OutputCollector;
  7. import org.apache.hadoop.mapred.MapReduceBase;
  8. import org.apache.hadoop.mapred.Reducer;
  9. import org.apache.hadoop.mapred.Reporter;
  10.  
  11. import scala.collection.JavaConversions._
  12.  
  13. class invertedReducer() extends MapReduceBase
  14.         with Reducer[Text, Text, Text, Text] {
  15.  
  16.     val finalValue = new Text();
  17.  
  18.     def reduce(key : Text,
  19.         values: Iterator[Text],
  20.         output: OutputCollector[Text, Text] ,
  21.         reporter: Reporter) {
  22.  
  23.     // Take all the values and concatinate them together with a , in between them
  24.         finalValue.set(values.foldLeft("")(_ +"," +_) )
  25.  
  26.         output.collect(key, finalValue);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement