reduce(reduceContext)

Description

Executes when the reduce entry point is triggered.

The logic in your reduce function is applied to each key, and its corresponding list of value. Only one key, with its corresponding values, is processed per function invocation. The function is invoked again for the next key and corresponding set of values.

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 contains:

  • The data to process during the reduce stage.

  • Logic that lets you save data to pass to the summarize stage.

  • Other properties you can use within the reduce function.

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

Errors

When an error is thrown, the behavior of the job varies depending on the setting of the retryCount configuration option.

If the function has been restarted for a key-value pair that it previously attempted to process, any errors logged during prior attempts can be accessed through 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 is not a functional example. For a complete script example, see Map/Reduce Script Samples.

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

          

Related Topics

General Notices