My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package shadoop

import SHadoop._
import java.util.Iterator
import org.apache.hadoop.fs._
import org.apache.hadoop.io._
import org.apache.hadoop.mapred._

object WordCount {

class Map extends MapReduceBase with Mapper[LongWritable, Text, Text, IntWritable] {

val one = 1

def map(key: LongWritable, value: Text, output: OutputCollector[Text, IntWritable], reporter: Reporter) =
(value split " ") foreach (output collect (_, one))
}

class Reduce extends MapReduceBase with Reducer[Text, IntWritable, Text, IntWritable] {
def reduce(key: Text, values: Iterator[IntWritable],
output: OutputCollector[Text, IntWritable], reporter: Reporter) = {
val sum = values reduceLeft ((a: Int, b: Int) => a + b)
output collect (key, sum)
}
}

def main(args: Array[String]) = {
val conf = new JobConf(classOf[Map])
conf setJobName "wordCount"

conf setOutputKeyClass classOf[Text]
conf setOutputValueClass classOf[IntWritable]

conf setMapperClass classOf[Map]
conf setCombinerClass classOf[Reduce]
conf setReducerClass classOf[Reduce]

conf setInputFormat classOf[TextInputFormat]
conf setOutputFormat classOf[TextOutputFormat[_ <: WritableComparable, _ <: Writable]]

conf setInputPath(args(0))
conf setOutputPath(args(1))

JobClient runJob conf
}

}
Show details Hide details

Change log

r37 by jonhnnyweslley on May 13, 2008   Diff
Initial version
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1344 bytes, 47 lines
Hosted by Google Code