list keys with key filters

Sam Lang samlang at gmail.com
Mon Apr 23 16:18:21 EDT 2012


On Apr 23, 2012, at 8:29 AM, Bryan Fink wrote:

> On Sat, Apr 21, 2012 at 12:39 PM, Sam Lang <samlang at gmail.com> wrote:
>> When I use ascii or json objects, I don't get the exception, and the keys get listed properly.  I assume that riak is trying to parse the data of my binary object and failing because the data isn't utf8 encoded.  Is it possible to do this without writing my own data extractor?  Is there a better way to list a subset of keys?
> 
> Hi, Sam.  Your intuition is correct: the bad_utf8_character_code error
> is coming from Riak trying to encode each object to JSON for your
> Javascript map phase to process.
> 
> If all you want is to get the keys back to your client, and you're
> using Riak 1.1 or newer with the latest Python client, then the
> simplest workaround is to call query.run() without any phases at all:
> 
>>>> query = client.add("foo")
>>>> query.add_key_filter("ends_with", "z")
>    <riak.mapreduce.RiakMapReduce object at 0x1006675d0>
>>>> v = query.run()
>>>> v[0]._key
>    u'baz'
> 
> Note that you will still end up with an encoding error if your keys
> cannot be encoded as JSON.

That worked, thanks Bryan!   Any way to avoid sending the values of the object to the client as well?
-sam

> 
> HTH,
> Bryan
> 
> P.S. If you're using an older version of Riak and/or the Python
> client, you may need to use the hack of a single-phase query, of just
> one reduce phase implemented by the Erlang function
> riak_kv_mapreduce:reduce_identity, instead of using the empty query.





More information about the riak-users mailing list