reduce(reduceContext)

Description

Runs when the reduce entry point is triggered.

The reduce function's logic is applied to each key and its list of values. Each call processes one key and its values, then runs again for the next set.

Data is provided to the reduce stage by one of the following:

  • The getInputData stage — if your script has no map function.

  • The shuffle stage — if your script uses a map function. The shuffle stage follows the map stage. Its purpose is to sort data from the map stage by key.

For information about the context object provided to this entry point, see reduceContext.

Returns

Void

Since

2015.2

Parameters

Parameter

Type

Required / Optional

Description

reduceContext

Object

Required

Object that has:

  • The data to process in the reduce stage.

  • Logic to save data and pass it to the summarize stage.

  • Other properties you can use in the reduce function.

For a description of each property in this object, see reduceContext Object Members.

Errors

When an error is thrown, the job's behavior depends on the retryCount setting.

If the function restarts for a key-value pair it already tried to process, you can see any past errors in reduceContext.errors.

In the summary stage, you can review all reduce stage errors by using reduceSummary.errors.

Syntax

The following code snippet shows the syntax for this member. It's not a functional example. For a complete script example, see SuiteScript 2.x Map/Reduce Script Code Samples.

            ...
function reduce(context)
{
    context.write({
        key: context.key , 
        value: context.values.length 
    }); 
}
... 

          

Related Topics

General Notices