Get Output from MapReduce Job

Hi Team,

My Requirement is to get count for my Timeseries type as it has huge data the fetchCount() method time out, hence i have opted to write a mapReduceJob to get count which as follows

var map = function(batch, objs, job, subBatch) {
var count;
objs.each(function(rsh) {
count = LogIn.fetchCount({filter:‘start>=dateTime("’+ new Date(‘2019-06-01’).toISOString().substring(0,10) +’") && == “’’”’});
return [count];
var spec = JSMapReduceSpec.make({
targetType: LogInSeries,
include: “id”,
limit: -1,
batchSize: 200,
map: map

var mrj = JS.mapReduce(spec);

Like to know where i can see count value and is this script give me right count.
Also any one have more efficient way to get row count please share the same.


There are two types you could use, MapResult and/or ReduceResult. Based on how you want to structure your output, you could potentially only use the MapResult Type. If you want to aggregate and get a count for the entire dataset, you will want to use the same outKey value for all your map tasks and then return the sum from your reduce function.

Thanks for reply.
It will be great if you share commands to achieve this


Commands to fetch the output?

For MapResult, you can fetch the output by using a combination of the run id for the MapReduce job and the output key. The runIdAndOutKey field is the partition key field for this Type and uses the following format, <runId>-<outKey>. You can get the run id from the MapReduce job record, c3ShowFunc(MapReduce, ‘run’), and then you would need to know the domain of the outKey values. If you have this information, you can then query this type using the following command, MapResult.fetch({filter: "runIdAndOutKey=='<runId>-<outKey>'", limit: 10}).

As you can see, it is not very straightforward to fetch this information from the MapResult Type. I would recommend having a reduce phase for your job and using the ReduceResult Type to fetch the result. You can then just use the run id from your MapReduce job to get the output results, ReduceResult.fetch({filter: "'<runId>'"}).

One thing to note, is that the output type for your map function above is not correct. You need to return a Map Type. In your case, if you wanted to get a count for the entire dataset, you could return something like {"count": count} from your map function and then your reduce function would be

function (outKey, interValues, job) {
return interValues.reduce((m,n)=>m+n);