Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send Parameters to a map reduce query

I'm writing a mapreduce query in erlang for Riak and I want to pass parameters into Riak using the HTTP API through curl on an Ubuntu terminal. The input to the query is a 2i query but I want a parameter to allow further filtering. I thought options was the keyword since the python client is what I'll be using in production, but it's inconvenient for proofing my Erlang, and it's the keyword that's always used on my team.

This is what I'm trying:

curl -X POST http://riakhost:port/mapred -H 'Content-Type: application/json' -d '{
    "inputs": {
        "bucket":"mybucket",
        "index":"field1_bin",
        "key":"val3"
    },
    "options": "test",
    "query": [
        {"map": {"language": "erlang", 
         "module": "mapreduce", 
         "function":"map"
        }},
    ]}'

On a three record set I am seeing:

["none", "none", "none"]

But I want:

["test", "test", "test"]

What is the format for arguments?

like image 562
Nickel Avatar asked Dec 01 '25 09:12

Nickel


1 Answers

I developed a set of configurable utility functions for Riak mapreduce in Erlang. As I wanted to be able to specify sets of critera, I decided to allow the user to pass configuration in as a JSON document as this works well for all client types, although other text representations should also work. Examples of how these functions are used from curl are available in the README.markdown file.

You can pass an argument to each individual map or reduce phase function through the 'arg' parameter. Whatever you specify here will be passed on as the final parameter to the map or reduce phase, see the example below:

"query":[{"map":{"language":"erlang","module":"riak_mapreduce_utils",
                 "function":"map_link","keep":false,
                 "arg":"{\"bucket\":\"master\"}"}},
like image 178
Christian Dahlqvist Avatar answered Dec 05 '25 03:12

Christian Dahlqvist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!