luwak questions

Bryan Fink bryan at basho.com
Wed Feb 23 09:57:12 EST 2011


On Tue, Feb 22, 2011 at 12:17 PM, francisco treacy
<francisco.treacy at gmail.com> wrote:
>> db.add({ bucket: 'luwak_tld', key_filters: [['starts_with', 'e276814e96e0616eb7c07d3bb744d333']]}).map(function(v) { return [1] }).run()
> POST /mapred
>> { message: 'HTTP error 500: {"error":"bad_json"}'
> , stack: [Getter/Setter]
> , statusCode: 500
> , notFound: false
> }
>
> but I get "bad_json" errors... Any other bucket works just fine. Why
> won't this work like a regular bucket?

The data stored in the luwak_tld Riak objects is an Erlang term that
is not directly convertible to JSON.  Riak is trying to convert that
object to JSON in order to hand it to the Javascript map function you
specified.

I recommend using riak_kv_mapreduce:reduce_identity/2 in a reduce
phase, instead of that Javascript map phase to assemble your keylist.
That will avoid the JSON conversion in two ways: it's Erlang native
(so it doesn't need the conversion), and reduce phases don't both with
reading the object from storage anyway.  If you really do need to look
at the object before deciding whether or not its key qualifies, you'll
need to code your logic in an Erlang function instead of Javascript.

If you need something closer to the Javascript function in your
example (which could be used to produce a count of the filtered keys,
instead of the keys themselves), I have a 'reduce_count_inputs'
function waiting in a pull request:
https://github.com/basho/riak_kv/pull/32

-Bryan




More information about the riak-users mailing list