MapReduce: map then inputs

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

MapReduce: map then inputs

Jimmy Ho
Hi guys,

I am sure I've seen it somewhere explaining what I'd like to do but can no longer find the link, hope someone could help?  Thanks.

I have a 'user' bucket which stores a list of keys within the data, pointing to other users as friends...

ie 
For User "mathew"

data: {
"friends": [ "john", "mark", "luke" ]
}


How would I get the keys of mathew's friends' friends via map reduce?

inputs: [["user", "mathew"]],
query: [ {map:... get a list of [[bucket, friend_key]] }

What is the next phase to read the bucket/key values as the new inputs?

Thanks guys,
Regards, Jimmy



_______________________________________________
riak-users mailing list
[hidden email]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: MapReduce: map then inputs

bryan-basho
Administrator
On Thu, Apr 4, 2013 at 3:59 PM, Jimmy Ho <[hidden email]> wrote:
> inputs: [["user", "mathew"]],
> query: [ {map:... get a list of [[bucket, friend_key]] }
>
> What is the next phase to read the bucket/key values as the new inputs?

Hi, Jimmy. If that map phase is producing a list of [bucket, key]
pairs, as you describe, the only thing you need to do to use them as
inputs is to add another map phase right after that one. So:

   inputs: [["user", "mathew"]],
   query: [ {map:… get a list of [[bucket, friend_key]] },
            {map:… do something with a friend}

Riak will handle reading each object and passing it into the map
function for you.

The special thing you may have been thinking of is "link-walking". If
instead of storing the list of friends in the object (or in addition
to), you stored their names in the Link metadata, you could use:

   inputs: [["user", "mathew"]],
   query: [ {link: {bucket:"user", tag:"friend"}},
            {map:… do something with a friend}

The 'link' phase would do the bucket-key-pair production for you. You
still use a map phase right afterward to work with the objects that
were linked.

Or, if you just wanted the friend/user objects, instead of some piece
of them, you could use the URL

   <a href="http://host:port/buckets/user/keys/mathew/user,friend,1">http://host:port/buckets/user/keys/mathew/user,friend,1

http://docs.basho.com/riak/latest/references/appendices/concepts/Links/

Cheers,
Bryan

_______________________________________________
riak-users mailing list
[hidden email]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
Loading...