Hi Rajat,

Answers inline below.

On 22 Feb 2012, at 16:44, Rajat Mathur wrote:

> I am running following IndexQuery :
> 
> <code>      
>         IntIndex intIndex=IntIndex.named("points");
> 
>     IndexQuery iQuery = new IntRangeQuery(intIndex,"fkUsers",1100,1300);
> 
>     MapReduceResult 
> resultInt=client.mapReduce(iQuery).addReducePhase(NamedErlangFunction.REDUCE_IDENTITY).execute();
> 
>     Collection<ArrayList> res=resultInt.getResult(ArrayList.class);
> 
>     Iterator<ArrayList> it=res.iterator();
> 
>     while ((it.hasNext())){
> 
>         ArrayList arrayList=it.next();
>         Bucket bucket= 
> client.fetchBucket(arrayList.get(0).toString()).execute();
>         for( int i=1;i<arrayList.size();i+=2){
>             IRiakObject 
> object=bucket.fetch(arrayList.get(i).toString()).execute();
>             log("Query Result : " + object.getValueAsString());
>     }
> 
> </code>    
> 
> I am not able to understand the exact result format getResult method of 
> MapReduceResult class is giving. Right now It is giving Buckets along with 
> ids 
> Is there any better method to parse result or it depends on my query ?

Your index query returns a list of Bucket/Key pairs. If you want all the data 
too you can fetch it or have your MapReduce query return it (see below.) If you 
just want the keys you can use the Bucket like this:

        List<String> keys =  
bucket.fetchIndex(IntIndex.named("points")).from(1100).to(1300).execute();

> Also please suggest other better methods(if any) for performing such queries .

Your code above is not ideal. If you want the actual object values back from an 
index range query then it might be better for MapReduce to return them rather 
than you sequentially fetching each one.

In which case you could use 

    MapReduceResult resultInt=client.mapReduce(iQuery)
        .addMapPhase(new NamedErlangFunction("riak_kv_mapreduce", 
"map_object_value"))
        .execute();

Then you can get your results as before. If you data payload is JSON then 
getResult(YourDomainClass.class) will use Jackson to automatically transform 
the result. Or you can use getResults(Map.class) to get a collection of 
Map.class instances (again, courtesy of Jackson).

If you want access to the raw JSON returned by the query getResultRaw() will 
get you it as a string.

Whether that is faster than firing up N threads and fetching the data in 
parallel depends…

BTW fetching a Bucket actually issues a request, so looping like that and 
fetching bucket after bucket is a bad idea, especially when 2i query can only 
be run on a single bucket, so you are in effect fetching the same bucket over 
and over again.

Cheers

Russell

> 
> 
> -- 
> Rajat Mathur
> B.Tech (IT) Final Year
> IIIT Allahabad
> 
> 09945990291
> 
> Find me @ Facebook
> Follow me @ Twitter
> _______________________________________________
> 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