learn_mapreduce 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/learn_mapreduce.rb +30 -5
- metadata +1 -1
data/lib/learn_mapreduce.rb
CHANGED
@@ -5,20 +5,45 @@ class MapReduce
|
|
5
5
|
@reducer = nil
|
6
6
|
end
|
7
7
|
|
8
|
-
#
|
9
|
-
#
|
8
|
+
# Set the mapper function
|
9
|
+
#
|
10
|
+
# Example:
|
11
|
+
# mr = MapReduce.new
|
12
|
+
# mr.map do |record|
|
13
|
+
# ...
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# Arguments:
|
17
|
+
# mapper: (block)
|
10
18
|
def map &mapper
|
11
19
|
@mapper = mapper
|
12
20
|
end
|
13
21
|
|
14
|
-
#
|
15
|
-
#
|
22
|
+
# Set the reducer function
|
23
|
+
#
|
24
|
+
# Example:
|
25
|
+
# mr = MapReduce.new
|
26
|
+
# mr.reduce do |key, list_of_values|
|
27
|
+
# ...
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# Arguments:
|
31
|
+
# reducer: (block)
|
16
32
|
def reduce &reducer
|
17
33
|
@reducer = reducer
|
18
34
|
end
|
19
35
|
|
20
36
|
# Run a MapReduce algorithm on the data provided
|
21
|
-
#
|
37
|
+
#
|
38
|
+
# Example:
|
39
|
+
# mr = MapReduce.new
|
40
|
+
# mr.run(data)
|
41
|
+
#
|
42
|
+
# Arguments:
|
43
|
+
# data: (array)
|
44
|
+
#
|
45
|
+
# Returns:
|
46
|
+
# [emitted, shuffled, output]
|
22
47
|
def run data
|
23
48
|
throw "Mapper missing!" unless @mapper
|
24
49
|
throw "Reducer missing!" unless @reducer
|