0

I am wondering if there is any difference between Riak.mapValuesJson() and JSON.parse(). I did not know about Riak.mapValuesJson() so in my map reduce functions in my Riak database i kept using JSON.parse() which worked I am not sure if there are extra optimizations or something that are in the built in riak version of if Riak.mapValuesJson() is an alias of JSON.parse()

Dmitri Zagidulin
  • 1,117
  • 9
  • 23
WojonsTech
  • 1,277
  • 1
  • 13
  • 28

1 Answers1

1

It uses JSON.parse()

See: https://github.com/basho/riak_kv/blob/master/priv/mapred_builtins.js

mapValues: function(value, keyData, arg) {
  if (value["not_found"]) {
    return [value];
  }
  var data = value["values"][0]["data"];
  if (Riak.getClassName(data) !== "Array") {
    return [data];
  }
  else {
    return data;
  }},
mapValuesJson: function(value, keyData, arg) {
  if (value["not_found"]) {
    return [value];
  }
  var newValues = Riak.mapValues(value, keyData, arg);
  return newValues.map(function(nv) { return JSON.parse(nv); });
}

Edit:

The first step is in the if statment to make sure there is a value to the object because riak will return an object even if there is no value, allowing you to set a value.

The next step is calling the parent object and calling that method using a call back to parse the now decoded json data, there should not be any major speed differance between the two it adds to if stements and initalizing an object, but it does make the calling of the map reduce easier, I would use this on smaller buckets and the JSON.pare() on larger buckets

WojonsTech
  • 1,277
  • 1
  • 13
  • 28
Brian Roach
  • 76,169
  • 12
  • 136
  • 161
  • my javascript is realy bad will you explain to what the extra things its doing before it calls mapValuesJson – WojonsTech Oct 14 '12 at 21:31