Java MR

niedomnie niedomnie at gmail.com
Wed Dec 3 08:35:35 EST 2014


Verified in Java - full code below - does not work - entry/key is in Riak -
and 
curl -s -X POST -H "Content-Type: application/json"
http://localhost:8098/mapred -d
'{"inputs":{"bucket":"bucket2","key_filters":[["starts_with", "key"]]},
"query":[{"map":{"language":"javascript", "source":"function(v) { return
[v.key]; }"}} ]}'
gives response ["key"] 

import com.basho.riak.client.api.RiakClient;
import com.basho.riak.client.api.commands.kv.StoreValue;
import com.basho.riak.client.api.commands.mapreduce.BucketMapReduce;
import com.basho.riak.client.api.commands.mapreduce.MapReduce;
import com.basho.riak.client.core.RiakFuture;
import com.basho.riak.client.core.RiakNode;
import com.basho.riak.client.core.query.Location;
import com.basho.riak.client.core.query.Namespace;
import com.basho.riak.client.core.query.RiakObject;
import com.basho.riak.client.core.query.functions.Function;
import com.basho.riak.client.core.util.BinaryValue;

import java.net.UnknownHostException;
import java.util.concurrent.ExecutionException;

/**
 * Created by ak on 12/3/14.
 */
public class Riak {

    public static void main(String args[]) throws UnknownHostException,
ExecutionException, InterruptedException {
        RiakClient client =
RiakClient.newClient(RiakNode.Builder.DEFAULT_REMOTE_PORT, "127.0.0.1");

        Namespace ns = new Namespace("default", "bucket2");
        Location loc = new Location(ns, "key");
        RiakObject ro = new RiakObject().setContentType("text/plain")
                .setValue(BinaryValue.create("value"));
        StoreValue sv = new
StoreValue.Builder(ro).withLocation(loc).build();
        client.execute(sv);

        BucketMapReduce bmr =
                new BucketMapReduce.Builder()
                        .withNamespace(ns)
                       
.withMapPhase(Function.newNamedJsFunction("Riak.mapValues"), false)
                        .build();
        MapReduce.Response response = client.execute(bmr);
        System.out.println("MR " +
response.getResultsFromAllPhases().size());

        client.shutdown();
    }
}



--
View this message in context: http://riak-users.197444.n3.nabble.com/Java-MR-tp4032117p4032213.html
Sent from the Riak Users mailing list archive at Nabble.com.




More information about the riak-users mailing list