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 |
|
12 | sc.parallelize(data, nPartitions)
|
13 | .reduceByKey(reducer, init)
|
14 | .collect(function(err, res) {
|
15 | console.log(res);
|
16 | console.assert(JSON.stringify(res) === JSON.stringify([['hello', 2], ['world', 1]]));
|
17 | sc.end();
|
18 | });
|