Edit: Looks like the concept is known as "forwarding and collecting". Going to see how this works in the Riak-Java client.
Right now performing a simple MapReduce in Riak that returns a list of keys of User
objects. To keep things simple, I want to simply map the values of a User
to the keys and return a list of users. Here's what I've got so far in Scala (using Java client) and FYI the key is composite and looks like clientId-userId
:
val map = new JSSourceFunction("""
function(riakObject){
var rolek = riakObject.key;
return [rolek];
}
""")
val reduce = new JSSourceFunction("""
function(value){
var returnValue=[], splitarr=[];
for(i=0;i<value.length;i++){
splitarr=String(value[i]).split("-");
returnValue = returnValue.concat([splitarr[1]]);
}
return returnValue;
}
""")
DB.client.mapReduce("rolesOfClientAdmins")
.addKeyFilter(new TokenizeFilter("-", 1))
.addKeyFilter(new MatchFilter(clientId))
.addMapPhase(map)
.addReducePhase(reduce)
.execute().getResult(classOf[String])
Do I add another Map phase after the Reduce phase? Do I need to somehow change buckets? Thanks for the help!