1 |
|
2 |
|
3 | var sc = require('skale-engine').context();
|
4 |
|
5 | var data = [['hello', 1], ['hello', 1], ['world', 1]];
|
6 | var nPartitions = 2;
|
7 |
|
8 | var init = 0;
|
9 |
|
10 | function reducer(a, b) {return a + b;}
|
11 | function combiner(a, b) {return a + b;}
|
12 |
|
13 | sc.parallelize(data, nPartitions)
|
14 | .aggregateByKey(reducer, combiner, init)
|
15 | .collect(function(err, res) {
|
16 | console.log(res);
|
17 | console.assert(JSON.stringify(res) === JSON.stringify([['hello', 2], ['world', 1]]));
|
18 | sc.end();
|
19 | });
|