Argument names and data types for "map" field/function of JSMapReduceSpec


#1

TLDR;
I’m trying to implement the map function for a JSMapReduceSpec, and I am hitting an issue that could be cleared up with some better documentation. Specifically, what should the function signature be and what data types are fed into these arguments by the MapReduce Framework?

THE DETAILS;
Currently the map field’s documentation is not very helpful:

/**
 * JS function code that implements map logic. (required)
 */
map: !clob

What Im trying to understand is how to implement my map function. I have the following:

function map(batch, objs) {
   var timeIdMap = {};
   objs.at('riskScores').each(function(series) {
     ...
   }
   ...
}

When I execute this function I get the following error:
wrapped org.mozilla.javascript.JavaScriptException: C3Error: [*]: Type Obj has no field "riskScores"
Which tells me that my objs argument is not the Type I expected it to be (the type defined in the JSMapReduceSpec.targetType).


#2

the map has the same signature as MapReduce.map.

You should make sure that when calling JS.mapReduce you specify a targetType that has a field ‘riskScores.’

If that is already the case, try

objs.eachRef(function(o) {
  o.at('riskScores')...
})

#3

eachRef fixed the problem. Thank you. Any idea why the “objs” are of type Obj instead of the Map Reduce’s targetType?

Ideally there would be a link in the documentation to the MapReduce.map documentation.