Skip to content

Instantly share code, notes, and snippets.

@markchadwick
Created October 27, 2008 02:02
Show Gist options
  • Save markchadwick/20001 to your computer and use it in GitHub Desktop.
Save markchadwick/20001 to your computer and use it in GitHub Desktop.
/*
* Silly Word Count example -- Mappers each get 1k input, 15 reducers, combiners currently broken
*/
/*
* Mapper
*/
function(key, value) {
var tokens = value.split(' ');
for(var i=0; i<tokens.length; i++) {
emit(tokens[i], 1);
}
}
/*
* Reducer
*/
function(key, values) {
var sum = 0;
for(var i=0; i<values.length; i++) {
sum += parseInt(values[i]);
}
emit(key, sum);
}
/*
* Really. That's it. Input can be hosted on any server that understand HEAD requests and
* the Range header. IE: Everything. Clients viewing /jobs/compute/JOB_ID will slowly
* compute the count.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment