سؤال

I could not make key_filter work with string_to_int transformation always get status code 500.

My object structure is the following:

{ "style": "double", "capacity": 6 }

My map function:

var client = require('riak-js')
    .getClient({host: "localhost", port: "10018"}),
    bucket = 'rooms';

client.mapreduce
.add({
    bucket: bucket, 
    key_filters: [["string_to_int"], ["and", [["greater_than", 1000]], [["less_than", 3000]]]]
})
.map('Riak.mapValuesJson')
.run(function(err, data){
    if (err) {
        console.log(JSON.stringify(err));
    } else {
        console.log(JSON.stringify(data));
    }
});

Response:

{ "message": "[object Object]", "statusCode": 500 }

P.S.

  • Riak 1.4.7
  • Erlang R15B01
  • nodejs v0.10.25
  • riak-js 0.10.2

UPDATE here are my request for keys and response:

curl http://mydomain.com:10018/riak/rooms?keys=true

{"props":{"name":"rooms","allow_mult":false,"basic_quorum":false,"big_vclock":50,"chash_keyfun": {"mod":"riak_core_util","fun":"chash_std_keyfun"},"dw":"quorum","last_write_wins":false,"linkfun":{"mod":"riak_kv_wm_link_walker","fun":"mapreduce_linkfun"},"n_val":3,"notfound_ok":true,"old_vclock":86400,"postcommit":[],"pr":0,"precommit":[],"pw":0,"r":"quorum","rw":"quorum","small_vclock":50,"w":"quorum","young_vclock":20},"keys":["6774","2205","6515","3812","2164","8677","3637","8701","2868","7249","3118","9781","4217","8432","4250","7551","7672","8736","7933"...

UPDATE 2 I did request with curl:

curl -v -X POST -H "Content-Type: application/json" http://mydomain.com:10018/mapred -d '{"inputs": {"bucket":"rooms","key_filters":[["string_to_int"],["and",[["greater_than",1000]],[["less_than",3000]]]]}, "query":[{"map":{"language":"javascript","name":"Riak.mapValuesJson"}}]}'

and got result:

{ "phase":"listkeys", "error":"function_clause", 
    "input":"{cover,[{1392993748081016843912887106182707253109560705024, 1392993748081016843912887106182707253109560705024]}],
        {<<\"rooms\">>,[{riak_kv_mapred_filters,string_to_int,[]},{riak_kv_mapred_filters,logical_and,[[[<<\"greater_than\">>,1000]],[[<<\"less_than\">>,3000]]]}]}}",
        "type":"error","stack":"[{riak_kv_pipe_listkeys,keysend,[error,{worker_crash,{badarg,[{erlang,list_to_integer,
    [\"5Ll5Gl3L61JX2mxYUvht6OMca4d\"],[]},{riak_kv_mapred_filters,'-string_to_int/1-fun-0-',1,
    [{file,\"src/riak_kv_mapred_filters.erl\"},
    {line,84}]},
    {lists,foldl,3,[{file,\"lists.erl\"},{line,1197}]},
    {riak_kv_coverage_filter,'-compose/2-fun-1-',2,[{file,\"src/riak_kv_coverage_filter.erl\"},{line,137}]},
    {riak_kv_vnode,'-fold_fun/3-fun-3-',5,[{file,\"src/riak_kv_vnode.erl\"},{line,1342}]},
    {bitcask_nifs,keydir_fold_cont,4,...},...]},...},...],...},...]"
}
هل كانت مفيدة؟

المحلول

I was able to replicate the error you got as a result of the curl request by putting a key in the bucket that could not successfully be converted to an integer by "string_to_int" in the key filter. I would recommend listing all keys in that bucket and verifying that they are all numeric.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top