I play around litle with riak riak-java-client.
Now I am having difficulty with custom javascript, I want to use collapse query in the summary.
If I use pure javascript functions as anon functions, they work well.
So here is what I did:
without commenting in app.conf
{js_source_dir, "/tmp/js_source"},
then I saved mylib.js in / tmp / js _source
var NS = (function() {
return {
mapHighValues: function(value, keydata, arg) {
var data = JSON.parse(value.values[0].data);
ejsLog('/tmp/map_reduce.log', JSON.stringify(data.High));
return [data.High];}
},
reduceSumHighValues: function(values) {
ejsLog('/tmp/map_reduce.log', "ReduceVals\n" + JSON.stringify(values));
return [values.reduce(function(prev, curr, index, array) {return prev + curr} ,0)];
}
}
})();
after that i restarted riak.
Here is the relevant Java code:
MapReduceBuilder builder = new MapReduceBuilder(new RiakClient("localhost"))
.setBucket("goog")
.map(JavascriptFunction.named("NS.mapHighValues"), false)
.reduce(JavascriptFunction.named("NS.reduceSumHighValues"), true);
MapReduceResponseSource response = builder.submit();
Anyone see my mistake?
Greetings
Apehanger
source
share