Skip to content

Commit

Permalink
Adding JavaScript Map/Reduce jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
mwinkle committed Jun 21, 2012
1 parent c4bc074 commit a90a263
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions javascriptMapReduce/countAndAverageDelayedFlights.js
@@ -0,0 +1,16 @@
var map = function (key, value, context){
var flightData = value.split(/,/);
var destAirport = flightData[4];
var arrivalDelay = flightData[0];
context.write(destAirport, arrivalDelay);
};

var reduce = function (key, values, context) {
var flightCount = 0;
var delaySum = 0;
while (values.hasNext()) {
flightCount++;
delaySum += parseInt(values.next());
}
context.write(key, flightCount + "\t" + (delaySum*1.0)/(flightCount*1.0));
};
11 changes: 11 additions & 0 deletions javascriptMapReduce/readme.md
@@ -0,0 +1,11 @@
Using JavaScript for MapReduce Jobs
============================
This shows a way to write MapReduce jobs using a JavaScript API

Setup
============================
Within the JavaScirpt console

#mkdir js
fs.put() // put the file into the .js folder
runJs("js/countAndAverageDelayedFlights.js", "asv://airlinedata/", "jsFlightMR2");

0 comments on commit a90a263

Please sign in to comment.