-
Notifications
You must be signed in to change notification settings - Fork 5
/
Program.cs
60 lines (56 loc) · 2.08 KB
/
Program.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
namespace MapReduce
{
public delegate IEnumerable<dynamic> IndexingFunc(IEnumerable<dynamic> source);
internal class Program
{
private static void Main()
{
var source = new[]
{
new {blog_id = 3, comments = 3},
new {blog_id = 5, comments = 4},
new {blog_id = 6, comments = 6},
new {blog_id = 7, comments = 1},
new {blog_id = 3, comments = 3},
new {blog_id = 3, comments = 5},
new {blog_id = 2, comments = 8},
new {blog_id = 4, comments = 3},
new {blog_id = 5, comments = 2},
new {blog_id = 3, comments = 3},
new {blog_id = 5, comments = 1}
};
var storageService = new Storage();
var mapReduceTask = new MapReduceTask
{
Map = docs => from post in docs
select new
{
post.blog_id,
comments_length = post.comments
},
Reduce = results => from agg in results
group agg by agg.blog_id
into g
select new
{
blog_id = g.Key,
comments_length = g.Sum(x => x.comments_length)
},
BatchSize = 3,
Storage = storageService,
Source = source
};
mapReduceTask.Execute();
foreach (var batch in storageService.GetBatchesFor(2))
{
foreach (var b in batch)
{
Console.WriteLine(b);
}
}
}
}
}