Getting MapReduce results on RIAK (using the Java client)

空扰寡人 提交于 2019-12-02 04:18:53

The JS function you're using doesn't do what you think it does :) It selects objects based on a field with a specific value you have to supply as an argument to the phase.

I think what you're looking for is mapValuesJson which will do what you seem to be wanting to do.

Also, you don't need a constructor at all in your POJO.

The code below should point you in the right direction (obviously this is super-simple with all public fields in the POJO and no annotations):

public class App {

    public static void main( String[] args ) throws IOException, RiakException
    {
        IRiakClient client = RiakFactory.httpClient();
        Bucket b = client.fetchBucket("test_mr").execute();

        b.store("myobject", new Person()).execute();
        IRiakObject o = b.fetch("myobject").execute();
        System.out.println(o.getValueAsString());


        BucketMapReduce m = client.mapReduce("test_mr");
        m.addMapPhase(new NamedJSFunction("Riak.mapValuesJson"), true);
        MapReduceResult result = m.execute();
        System.out.println(result.getResultRaw());
        Collection<Person> tmp = result.getResult(Person.class);

        for (Person p : tmp)
        {
            System.out.println(p.data);
        }


        client.shutdown();
    }
}

class Person 
{
    public String id = "12345";
    public String name = "my name";
    public String lastUpdate = "some time";
    public String data = "some data";


}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!