UNPKG

479 BJavaScriptView Raw
1#!/usr/bin/env node
2
3var sc = require('skale-engine').context();
4
5var data = [['hello', 1], ['hello', 1], ['world', 1]];
6var nPartitions = 2;
7
8var init = 0;
9
10function reducer(a, b) {return a + b;}
11function combiner(a, b) {return a + b;}
12
13sc.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 });