Parameters
EMR Workflow supports built-in time parameters, task-level parameters (local parameters), workflow-level parameters (global parameters), and project-level parameters. You can also pass parameters between tasks.
Parameter configuration
Built-in time parameters
Definition
Built-in time parameters require no definition. You can use them directly in any task.
Usage
EMR Workflow supports built-in time parameters in the $[...] syntax. The $[yyyyMMddHHmmss] format can be customized, for example, $[yyyyMMdd], $[HHmmss], or $[yyyy-MM-dd]. You can also modify time parameters in the following ways:
-
Use the
add_months()function to add or subtract months. The first argument,[yyyyMMdd], specifies the return time format. The second argument is the month offset, specifying the number of months to add or subtract.-
N years later:
$[add_months(yyyyMMdd,12*N)] -
N years earlier:
$[add_months(yyyyMMdd,-12*N)] -
N months later:
$[add_months(yyyyMMdd,N)] -
N months earlier:
$[add_months(yyyyMMdd,-N)]
-
-
Perform direct arithmetic by adding or subtracting numbers after the custom format.
-
N weeks later:
$[yyyyMMdd+7*N] -
N weeks earlier:
$[yyyyMMdd-7*N] -
N days later:
$[yyyyMMdd+N] -
N days earlier:
$[yyyyMMdd-N] -
N hours later:
$[HHmmss+N/24] -
N hours earlier:
$[HHmmss-N/24] -
N minutes later:
$[HHmmss+N/24/60] -
N minutes earlier:
$[HHmmss-N/24/60]
-
Task-level parameters (local parameters)
Task-level parameters apply only to a specific task node. A Custom Parameters configured on the task definition page applies only to that task by default. With parameter passing configured, you can pass the parameter to downstream tasks.
Definition
On the task definition page, click the
icon next to Custom Parameters to add a custom parameter. In the script editor, enter echo ${dt}. Reference the custom parameter in a bash script using the ${ParameterName} syntax.
Parameter example:
-
dt: The name of the custom parameter. -
IN: The parameter applies only to the current task node. If set to OUT, you can pass it to downstream tasks. -
VARCHAR: The data type of the parameter. -
$[yyyy-MM-dd]: The value of the parameter.
Usage
In a task definition, use the ${...} syntax to reference a local parameter.
Workflow-level parameters (global parameters)
Global parameters apply to all task nodes within a workflow. You can configure them when you save the workflow definition.
Definition
When you save a workflow definition, you can add a Global Parameters by specifying its name and value.
In the Global parameters section at the bottom of the Basic Information dialog box, click the plus (+) button to add a parameter, and then enter param for the name and 123 for the value.
Usage
In your task definitions, use the ${...} syntax to reference global parameters.
Project-level parameters
Project-level parameters apply to all workflows within a project.
Definition
In Project Management, navigate to the page. Click Create project-level parameter and specify the parameter name and value.
Usage
In a task definition, use the ${...} syntax to reference project-level parameters.
Parameter passing
In YARN mode, passing dynamic parameters to a local cluster is not supported.
To configure parameter passing, define a custom parameter in the upstream task with its direction set to OUT. This makes the parameter available to downstream tasks. Add an echo statement in the upstream task's script in the format echo "#{setValue(key=value)}". In this format, key is the name of the OUT-type parameter, and value is the value to pass. The value can be a constant, the value of another task parameter, or a bash variable. Downstream tasks can then reference the parameter directly using the ${...} syntax without additional configuration.
Pass a constant
For example, add a custom parameter res with an OUT direction, and use echo "#{setValue(res=1234)}" to pass the parameter res=1234 to downstream tasks.
Pass a task parameter
For example, add a parameter param=123 with an IN direction and a custom parameter res with an OUT direction. Then, use echo "#{setValue(res=${param})}" to pass the value of param (which is 123) to downstream tasks.
Pass a bash variable
For example, add a custom parameter res with an OUT direction. Then, use echo "#{setValue(res=${RESULT})}" to pass the value of the RESULT bash variable (for example, 123) to downstream tasks.
Parameter priority
In EMR Workflow, parameter values can come from the following sources:
If parameters with the same name are defined in multiple scopes, EMR Workflow resolves the conflict using the following priority (from highest to lowest): task-level parameter (local parameter) > parameter passed from an upstream task > workflow-level parameter (global parameter) > project-level parameter.