list keys with key filters

Bryan Fink bryan at basho.com
Mon Apr 23 09:29:51 EDT 2012


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.

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