On 14 Sep 2012, at 14:24, Deepak Balasubramanyam wrote:

> Hi,
> 
> I've written a map reduce query on the riak java client like so...
> 
> client.mapReduce(BUCKET).addKeyFilter(keyFilter)
>                     .addLinkPhase(BUCKET, "_", false)
>                     .addMapPhase(new NamedJSFunction("Riak.mapValuesJson"), 
> false)
>                     .addReducePhase(phaseFunction).execute();
> Collection<MyType> types = result.getResult(MyType.class);
> 
> This is the class definition for MyType
> 
> public class MyType
> {
>     @RiakKey
>     private String myKey;
>     private String property1;
>     private String property2;
> 
>     /*  Getters / Setters go here */
> }
> 
> When the object mapper deserializes the results into Collection<MyType>, none 
> of the types have the myKey property populated in them. When I debugged the 
> calls made by riak I realized that the result of the /mapred call does not 
> contain any key information in the body. It only contains the value that each 
> key represents. So that explains why the keys are null in the result.

The Java client doesn't add the value of the @RiakKey field to the value stored 
in riak.

> 
> On the contrary, a link walk in riak returns the Location header for each 
> multipart form entry in the response (Location: /riak/bucket/key). So I guess 
> there is at least some way to tweak a client to parse the location to get the 
> keys, but you lose out on the map-reduce goodness. 
> 
> Is there some way a map-reduce query can be formed to allow the resulting 
> type's RiakKey to be populated ? What are my options ?

A custom Map function may do what you want. Get the Key from the Key Data 
passed to the Map function and add it to the JSON value returned. Jackson 
should then take care of de-serialising it into your values.

Cheers

Russell

> 
> Thanks
> Deepak Bala
> _______________________________________________
> riak-users mailing list
> riak-users@lists.basho.com
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com


_______________________________________________
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to