Actually, I'm going to look into switching from the RawClient to a normal
client. That should make this easier.

On Tue, Oct 25, 2011 at 12:48 PM, Alexander Robbins <
a...@languagecomputer.com> wrote:

> That code snippet isn't working because I've got a RawClient instance and
> its mapReduce method wants a MapReduceSpec. I ran into this problem while
> trying to use search also. I ended up making a search object and then
> serializing it to json and providing it to the MapReduceSpec constructor,
> then passing the resulting MapReduceSpec into the mapReduce method on
> RawClient. Is there a better way? I considered just using String.format to
> put the variables into a handwritten json string and using that to
> instantiate the MapReduceSpec.
>
> Thanks!
> Alex
>
> My gross method of making a MapReduceSpec:
>     final Map<String, Object> mapReduceObject = new HashMap<String,
> Object>();
>     final Map<String, Object> inputs = new HashMap<String, Object>();
>     final List<Map> query = new ArrayList<Map>();
>     final List<String> searchTerms = new ArrayList<String>();
>     searchTerms.add(bucket);
>     searchTerms.add(terms);
>     inputs.put("module", "riak_search");
>     inputs.put("function", "mapred_search");
>     inputs.put("arg", searchTerms);
>     final Map<String,String> reduce = new HashMap<String,String>();
>     reduce.put("language", "erlang");
>     reduce.put("module", "riak_kv_mapreduce");
>     reduce.put("function", "reduce_identity");
>     final Map<String,Map<String,String>> map1 = new
> HashMap<String,Map<String,String>>();
>     map1.put("reduce", reduce);
>     query.add(map1);
>     mapReduceObject.put("inputs", inputs);
>     mapReduceObject.put("query", query);
>     final MapReduceSpec spec = new MapReduceSpec(new
> Gson().toJson(mapReduceObject));
>
>
>
> On Tue, Oct 25, 2011 at 10:43 AM, Russell Brown <russel...@basho.com>wrote:
>
>>
>> On 25 Oct 2011, at 16:09, Alexander Robbins wrote:
>>
>> The M/R job over the http api seems to be working to me.
>>
>> curl -X POST http://192.168.1.39:8098/mapred -H "Content-Type:
>> application/json" -d @query.json
>>
>> query.json:
>> {"inputs":{"bucket":"mentions","index":"docUID_bin","key":"5b9d1a6250dbd3e77ff004a12d06958745ee32844ad4aa668001bbe69b5efcf8"},"query":[{"reduce":{"language":"erlang","module":"riak_kv_mapreduce","function":"reduce_identity","arg":"{reduce_phase_only_1,
>> true}"}}]}
>>
>> Results:
>>
>> [["mentions","1907d031c88b8df2fc5128114615133d4184cedaea55964c3cee0ef9fe566f13"],["mentions","1bb5ce4aba0bf240698876530948c807d50e6f04a7358b7514c756dd295775ae"],["mentions","1f5f8f78951c6842ad6bcc96e3839ca8240b71372d2ab4826411fdfc84fedeb1"],["mentions","330856dabfa3a1c5b9ca8051686d8d7f387a23c795493a4e8f33d84861756d4f"],["mentions","338fffb9740b2f0c50b2da52a73b4861be318868082db3748eb95a47654981bd"],["mentions","5eef2b9cd6f7faf34548c9700069527287574690ab3dabf4c4f186753ffc5417"],["mentions","7ec9217a7a87c9e43a94170bb1ab8c13566233823ef6f77ef9c455a289c4bdf8"],["mentions","a588d7f0fb413d52a895a5d7e7fcfc966e9a56c42456e7821d2e5fa93b5671ba"],["mentions","aaacde92acf2c61abf9a4104f263283aed6233da08efb6ebbf13f83dfcfa1e7c"]]
>>
>> Looks good to me. It has an extra "mentions" term, but I think the java
>> client explicitly drops that when converting the m/r results.
>>
>>
>> That is what I think the culprit is (dropping the bucket from the return.)
>> Thanks for helping track it down. I'm going to spend some time trying to
>> recreate it so I can fix it. I've opened a bugzilla ticket for it here
>> https://issues.basho.com/show_bug.cgi?id=1262
>>
>> Thanks again, hope to have something for you soon. In the meantime, a work
>> around would be to use an M/R job from the PB client like this (it is a bit
>>  more verbose, sorry)
>>
>> // get your PB client as before
>>  IndexQuery q = new BinValueQuery(BinIndex.named("docUID"), "mentions",
>> "5b9d1a6250dbd3e77ff004a12d06958745ee32844ad4aa668001bbe69b5efcf8");
>>  MapReduceResult result =
>> client.mapReduce(q).addReducePhase(NamedErlangFunction.REDUCE_IDENTITY, 
>> "{reduce_phase_only_1,
>> true}").execute();
>> Collection<String[]> r = result.getResult(String[].class);
>>
>> This will get you a collection of two tuples where the first element is
>> the bucket and the second the key.
>>
>> Let me know if that works for you in the interim.
>>
>> Cheers
>>
>> Russell
>>
>>
>>
>> Alex
>>
>> On Tue, Oct 25, 2011 at 9:12 AM, Russell Brown <russel...@basho.com>wrote:
>>
>> _______________________________________________
>> 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