map(mapContext)

Description

Executes when the map entry point is triggered.

The logic in your map function is applied to each key-value pair that is provided by the getInputData stage. One key-value pair is processed per function invocation, then the function is invoked again for the next pair.

The output of the map stage is another set of key-value pairs. During the shuffle stage that always follows, these pairs are automatically grouped by key.

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

Returns

Void

Since

2015.2

Parameters

Parameter

Type

Required / Optional

Description

mapContext

Object

Required

Object that contains:

  • The key-value pairs to process during the map stage.

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

  • Other properties you can use within the map function.

For a description of each property in this object, see mapContext 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 mapContext.errors.

In the summary stage, you can review all map stage errors by using mapSummary.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.

            // Add additional code
...
function map(context)
{
    for (var i = 0; context.value && i < context.value.length; i++)
        if (context.value[i] !=== ' ' && !PUNCTUATION_REGEXP.test(context.value[i]))
           {
                context.write({
                    key: context.value[i], 
                    value: 1 
                }); 
           }
}

...
// Add additional code 

          

Related Topics

General Notices