My favorites
|
Sign in
jweslley
Jonhnny Weslley's personal projects
Project Home
Downloads
Wiki
Issues
Source
Checkout
|
Browse
|
Changes
|
r255
Source path:
svn
/
trunk
/
scala
/
shadoop
/
src
/
main
/
scala
/
shadoop
/
WordCount.scala
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:
/trunk/scala/shadoop/.classpath
/trunk/scala/shadoop/.project
/trunk/scala/shadoop/LICENSE.txt
/trunk/scala/shadoop/README.txt
/trunk/scala/shadoop/input
/trunk/scala/shadoop/input/file01
/trunk/scala/shadoop/input/file02
/trunk/scala/shadoop/output
.../scala/shadoop/output/part-00000
/trunk/scala/shadoop/pom.xml
/trunk/scala/shadoop/src
/trunk/scala/shadoop/src/main
/trunk/scala/shadoop/src/main/scala
...a/shadoop/src/main/scala/shadoop
...main/scala/shadoop/SHadoop.scala
...in/scala/shadoop/WordCount.scala
/trunk/scala/shadoop/target
...p/target/shadoop-0.0.1-alpha.jar
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 1344 bytes, 47 lines
View raw file
Hosted by