The aim of this project is to implement a distributed, fault-tolerant MapReduce framework using elixir language.
First, open the ternimal, go to the application root and then run:
iex -S mix
Then you have to define two functions, map
and reduce
, depending on the problem you want to solve.
Let's say you have a list of connections in the format {source, target} and you want to calculate for each node the list of
sources that have connections to it. Here's how you can define your map & reduce functions:
fn mapper {source, target} -> %{target => [source]} end
fn reducer a,b -> %{get_key(a) => Enum.concat(get_value(a), get_value(b))} end
note
: get_key
and get_value
are two functions that assume the given input is a map with only one key and value, and they return the key or value for that map.
Then you can use the MapReduce module to calculate the ansewr for your desired list:
list = [{1, 3}, {2, 3}, {4, 5}, {5, 6}]
MapReduce.solve(list, mapper, reducer) # you should get %{3 => [1, 2], 5 => [4], 6 => [5]}
Note that here we used anonymous functions, you can use normal functions but you have to use the syntax MapReduce.solve(list, &mapper, &reducer)
in that case
The source code is released under MIT License.
Check LICENSE for more information.