mapreduce javascript 函数错误

mapreduce javascript function error

我无法获得 erlang 函数 运行 所以尝试使用 Javascript 如下:

curl -XPOST http://localhost:8098/mapred \
  -H "Content-Type: application/json" \
  -d @- \
<<EOF
{
  "inputs":"logs",
  "query":[{
    "map":{
      "language":"javascript",
      "source":"function(riakObject, keydata, arg) {
        var m = riakObject.values[0].data.match(/^INFO.*cart/);
        return [(m ? m.length : 0 )];
      }"
    },
    "reduce":{
      "language":"javascript",
      "source":"function(values, arg){
        return [values.reduce(
          function(total, v){ return total + v; }, 0)
        ];
      }"
    }
  }]
}
EOF

似乎也不适用于 JS。 Shell 只是挂起,根本没有 return。请提出建议。

** 更新 **

今天我尝试时看到以下错误:

An error occurred parsing the "query" field.
["Unrecognized format of query phase:\n   ",
 [123,
  [34,<<"map">>,34],
  58,
  [123,
   [34,<<"language">>,34],
   58,
   [34,<<"javascript">>,34],
   44,
   [34,<<"source">>,34],
   58,
   [34,
    <<"function(riakObject, keydata, arg) {        var m = riakObject.values[0].data.match(/^INFO.*Milk/);        return [(m ? m.length : 0 )];      }">>,
    34],
   125],
  44,
  [34,<<"reduce">>,34],
  58,
  [123,
   [34,<<"language">>,34],
   58,
   [34,<<"javascript">>,34],
   44,
   [34,<<"source">>,34],
   58,
   [34,
    <<"function(values, arg){        return [values.reduce(          function(total, v){ return total + v; }, 0)        ];      }">>,
    34],
   125],
  125],
 "\n\nValid formats are:\n   {\"map\":{...spec...}}\n   {\"reduce\":{...spec...}}\n   {\"link:{...spec}}\n"]

查询元素应该是一个对象列表,其中 "map" 和 "reduce" 位于离散对象中。您的 JSON 将它们作为同一对象的属性。

这对我有用:

curl -XPOST http://localhost:8098/mapred -H "Content-Type: application/json" -d  '{
  "inputs":"logs",
  "query":[
    {"map":{
      "language":"javascript",
      "source":"function(riakObject, keydata, arg) {
        var m = riakObject.values[0].data.match(/^INFO.*cart/);
        return [(m ? m.length : 0 )];
      }"
    }},
    {"reduce":{
      "language":"javascript",
      "source":"function(values, arg){
        return [values.reduce(
          function(total, v){ return total + v; }, 0)
        ];
      }"
    }}
  ]
}'