Created
August 2, 2012 23:15
-
-
Save vincentmac/3241784 to your computer and use it in GitHub Desktop.
js:riak mr example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"inputs":"goog", | |
"query":[ | |
{"map":{ | |
"language":"javascript", | |
"source": | |
"function(value, keyData, arg) { | |
var data = Riak.mapValuesJson(value)[0]; | |
var month = value.key.split('-').slice(0,2).join('-'); | |
var volume = data.Volume; | |
var adj_close = data['Adj. Close']; | |
var obj = {}; | |
obj[month] = volume * adj_close; | |
return [ obj ]; | |
}" | |
} | |
}, | |
{"reduce":{ | |
"language":"javascript", | |
"source": | |
"function(values, arg) { | |
return [ values.reduce(function(acc, item) { | |
for (var month in item) { | |
if (acc[month]) { | |
acc[month] = (acc[month] < item[month]) ? item[month] : acc[month]; | |
} else { | |
acc[month] = item[month]; | |
} | |
} | |
return acc; | |
})]; | |
}", | |
"keep":true} | |
}, | |
{"reduce":{ | |
"language":"javascript", | |
"source": | |
"function(values, arg) { | |
var maxtrade = { day:'', value:0}; | |
for (var key in values[0]){ | |
if (maxtrade.value < values[0][key]) { | |
maxtrade.value = values[0][key]; | |
maxtrade.day = key; | |
} | |
} | |
return [maxtrade]; | |
};", | |
"keep":true} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment