-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
80 lines (67 loc) · 2 KB
/
Copy pathREADME
File metadata and controls
80 lines (67 loc) · 2 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
hadoop-jruby-adapter
1. Summary
This library provides adapter classes to write MapReduce in JRuby.
Developed for hadoop-0.23.0-cdh4b1, but should work fine as long as using new API(org.apache.hadoop.mapreduce).
2. How to use
- write main class in JRuby
- write Mapper and Reducer in JRuby
- set mapper and reducer class in hadoop-jruby-adapter-conf.xml
- compile jruby classes using jruby --javac
3. Sample
# mapper
class CountMapper
def initialize
@one = IntWritable.new(1)
@word = Text.new
end
java_signature 'void map(Writable, Writable, Mapper.Context)'
def map(key, value, context)
#puts "mapper: #{value}"
value.to_s.split.each do |i|
@word.set(i)
context.write(@word, @one)
end
end
end
# reducer
class CountReducer
java_signature 'void reduce(Writable, Iterable, Reducer.Context)'
def reduce(key, values, context)
#puts "reducer: #{key}"
sum = 0
values.each do |i|
sum += i.get
end
context.write key, IntWritable.new(sum)
end
end
# main
class MapReduceTestMain
java_signature 'void main(String[])'
def self.main(args)
puts "MapReduceTest"
job = Job.instance
# set actual mapper via hadoop-jruby-adapter-conf.xml
job.mapperClass = MapperAdapter.java_class
puts job.mapperClass
job.mapOutputKeyClass = Text.java_class
puts job.mapOutputKeyClass
job.mapOutputValueClass = IntWritable.java_class
puts job.mapOutputValueClass
# set actual reducer via hadoop-jruby-adapter-conf.xml
job.reducerClass = ReducerAdapter.java_class
puts job.reducerClass
job.outputKeyClass = Text.java_class
puts job.outputKeyClass
job.outputValueClass = IntWritable.java_class
puts job.outputValueClass
FileInputFormat.addInputPath job, Path.new(args[0])
FileOutputFormat.setOutputPath job, Path.new(args[1])
job.waitForCompletion true
end
end
4. Limitation
Currently support only Mapper and Reducer.
5. License
Copyright (c) 2012 Akira Kuroda <akuroda@gmail.com>
Released under MIT License.