Fwd: Re: Querying Examples

Sean Cribbs seancribbs at gmail.com
Wed Feb 3 20:55:32 EST 2010

Forwarding to the list since I screwed that part up.

-------- Original Message --------
Subject: 	Re: Querying Examples
Date: 	Thu, 4 Feb 2010 01:45:55 +0000
From: 	Jason Tanner <jt4websites at googlemail.com>
To: 	Sean Cribbs <seancribbs at gmail.com>

Hi Sean,

I've been scratching my head over this for a few days now.

It seems so easy, now I have an example to look at.

Thanks very much.


On Thu, Feb 4, 2010 at 12:47 AM, Sean Cribbs <seancribbs at gmail.com 
<mailto:seancribbs at gmail.com>> wrote:


    Your map function (in Erlang or JS) needs to return a list of the
    mapped values, so if you are filtering by age, write a function like

    FilterAgeLessThan = fun(O,_,Limit) ->
        PList = riak_object:get_value(O),
        case proplists:get_value(age, PList) of
            A when A < Limit -> [O];
            _ -> []

    Then that phase can be created like so:

    {map, {qfun, FilterAgeLessThan}, 50, false}

    You would create a similar function for your home_town property, or
    generalize the above to take any property/value combination, and
    then create one for equality.  You shouldn't need a reduce phase for
    that query.


    On 2/3/10 5:57 PM, Jason Tanner wrote:


        Im trying to work out how, using riak's *erlang* *map reduce*
        *Interface* I would do something equivalent to the following SQL:

        SELECT *
            FROM Users
          WHERE age < 50
              AND  home_town = "London"

        So assuming I had a bucket "Users" keyed on some unique user-id
        where the object value associated with the users key was
        structured something like:

        [ {first_name, "Bob"},
          {last_name, "Smith" },
          {age,           30 },
          {home_town, "London" } ]

        (Lets also assume that the "Users" bucket contains several
        thousand user key/value entries, and I want to produce a subset
        of them based on the filter criteria above in the SQL)

        What could my erlang map function look like ?
        What could my erlang reduce function look like ?

        Unfortunately, all the examples I have been able to find, seem
        to be related to counting and accumulating entries.



        riak-users mailing list
        riak-users at lists.basho.com <mailto:riak-users at lists.basho.com>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20100203/415b37ed/attachment.html>

More information about the riak-users mailing list