All Products
Search
Document Center

E-MapReduce:Variable management

Last Updated:Mar 25, 2026

Variables help you avoid hardcoding repeated values across SQL jobs, batch jobs, and workflows. Instead of updating the same date string in multiple places, you define it once as a variable and reference it with ${variable_name}. This topic explains how to add and use variables in each supported scenario.

Variable types and scope

A variable consists of a name and a value. Reference a variable using the ${Variable name} format. When a job or workflow runs, the system replaces each variable reference with the configured value.

EMR Serverless Spark supports two variable types:

TypeDescriptionCan modify nameCan modify value
Custom variablesDefined by you. Set any name and value to match your business logic.YesYes
Built-in variablesProvided by the system. All are date and time variables. Default value is the day before the current day (UTC+8).NoNo

Variables are scoped to the context where they are defined:

  • Job-level variables: Defined and used within a single Spark SQL or batch job.

  • Workflow-level variables: Applied to all nodes in a workflow.

  • Node-level variables: Applied to a single node within a workflow.

Priority rule: When the same variable name is configured at both the workflow level and a node level, the node-level value takes precedence.

Data development variables

Add a variable in a Spark SQL job

For information about how to develop a Spark SQL job, see Get started with the development of Spark SQL jobs.

  1. On the configuration tab of a Spark SQL job, copy the following code to the code editor:

    CREATE TABLE IF NOT EXISTS students_info (
      name VARCHAR(64),
      address VARCHAR(64)
    )
    USING PARQUET
    PARTITIONED BY (data_date STRING);
    
    INSERT OVERWRITE TABLE students_info PARTITION (data_date = '${my_date}') VALUES
      ('Ashua Hill', '456 Erica Ct, Cupertino'),
      ('Brian Reed', '723 Kern Ave, Palo Alto');
  2. In the right-side navigation pane, click Variables Management. In the Variables Management panel, enter a value in the Variable Value column. In this example, the variable value is 2025-04-15.

    image

  3. In the code editor, enter and run the following statement to query table data:

    SELECT * FROM students_info;

    On the Execution Results tab in the lower part, verify that the variable is correctly parsed.

    image

Add a variable in a batch job

For information about how to develop a batch or streaming job, see Develop a batch or streaming job.

  1. On the configuration tab of a batch job, enter a variable name in the Execution Parameter field. In this example, enter ${osspath}.

  2. In the right-side navigation pane, click Variables Management. In the Variables Management panel, enter a value in the Variable Value column.

    image

Use a built-in variable

Built-in variables are system-provided date and time variables. Their default value is the day before the current day (UTC+8). You cannot modify built-in variable names or values.

The following table lists all supported built-in variables.

VariableData typeFormatExample
{data_date}strYYYY-MM-DD2023-09-18
{ds}str
{dt}str
{data_date_nodash}strYYYYMMDD20230918
{ds_nodash}str
{dt_nodash}str
{ts}strYYYY-MM-DDTHH:MM:SS2023-09-18T16:07:43
{ts_nodash}strYYYYMMDDHHMMSS20230918160743

To use a built-in variable, copy the following code to the code editor of a Spark SQL job and run it:

CREATE TABLE IF NOT EXISTS students_address (
  name VARCHAR(64),
  address VARCHAR(64)
)
USING PARQUET
PARTITIONED BY (data_date STRING);

INSERT OVERWRITE TABLE students_address PARTITION (data_date = '${ts}') VALUES
  ('Ashua Hill', '456 Erica Ct, Cupertino'),
  ('Brian Reed', '723 Kern Ave, Palo Alto');

SELECT * FROM students_address;

The following figure shows the output.

image

View or modify a variable value

  1. In the right-side navigation pane of the configuration tab, click Variables Management.

  2. In the Variables Management panel, view the variables referenced in the job.

  3. In the Variable Value column, view or modify the value of a custom variable.

    image

Workflow variables

Workflows support two variable scopes: workflow-level and node-level. When the same variable is configured for both a workflow and one of its nodes, the node-level variable takes precedence.

You cannot modify the names of built-in variables.

Add a workflow-level variable

In the Create Workflow panel, click the right arrow next to Variable Settings. In the Variable Settings section, click Add to add a variable. When the workflow is scheduled, the variable is automatically replaced with the specified value.

image

Select a variable value from the Variable Value drop-down list and modify the value based on your requirements.

image

Add a node-level variable

In the Add Node panel, configure the Source File Path parameter. Then, click Add next to Node-level Variables.

image

Select a variable value from the Variable Value drop-down list and modify the value based on your requirements.

image