Variables

更新时间:
复制 MD 格式

This topic explains the variables used in task orchestration.

Variable overview

Variables are dynamic values in a task flow, categorized as system variables, time variables, and non-time variables. You can reference any variable within a node using the${varName} syntax.

System variables

System variables are predefined values, such as the current task flow ID and the run time of the task flow.

Note

If a custom variable shares a name with a system variable, its value overrides the system variable's value, giving the custom variable higher priority.

Time variables

  • Task flow variable (global variable): A task flow variable is calculated by applying a time offset to the data timestamp. By default, the data timestamp is the run time minus one day. As a global variable, it is available to all nodes in the current task flow.

    Note

    You can configure a task flow variable on any node in a task flow. The configuration is automatically synchronized to all other nodes.

  • Node variable: A time variable created by applying a time offset to the built-in bizdate (T-1) variable. A node variable is scoped to its defining node.

    For example, if the current date is August 22, 2023, and you apply a time offset of +1 day, the variable's value becomes August 23, 2023.

Non-time variables

  • Task flow constant (global variable): A task flow constant is a fixed value that can be used in all nodes within the current task flow.

  • Input variable: The system automatically populates input variables. You can reference an input variable in the SQL statements of the current node by using the ${var_name} syntax or as a conditional variable in a Conditional Branch node. Input variables include:

    • Upstream variable: An output variable from an upstream node.

    • Status variable: For more information, see Status variables.

    • System variable: For more information, see System variables.

  • Output variable: You define and assign a value to an output variable on the current node. Downstream nodes can then access and reference it.

    For example, if you configure an output variable in a Script node, it can be referenced in the SQL statements of a downstream node.

  • Output variable from a Single Instance SQL node: You can use a Single Instance SQL node to define a result set from an SQL query. This result set forms a two-dimensional matrix. During variable definition, you can extract a single element or concatenate all values from a row or column.

  • Script output variable: If the last line of a script's output is a JSON object in the format{ key1: value1, key2: value2, … }, and the values are of the String type, the script task automatically parses the JSON key-value pairs. This creates a variable namedkey, and the value of the variablekey is set to the corresponding value. You can reference the variable as${key}.

    For example, if the last line of the script isecho {"hello": "world"}, the script task creates a variable namedhello, and the value ofhello is world.

Configure time variables

Parameter

Description

Variable name

Enter the name of the custom variable.

Note

To delete a configured variable, click the 删除-变量 icon.

Variable rule

Configure the rules for the time variable.

  • Time format: Specify the desired time format. For more information, see Time formats.

  • Time offset: A time variable is calculated by applying an offset to the data timestamp (bizdate), which defaults to the day before the task flow's run time.

    For example, consider a variable named6_month_ago with the time format yyyy-MM-dd and an offset of -6 months. If the run time is 2021-08-12 (making bizdate 2021-08-11), the value of the${6_month_ago} variable is 2021-02-11.

    Using month or year as the offset unit can result in non-continuous date sequences. For a continuous daily sequence, use day as the offset unit.

Note

After you configure a time variable, you can reference it in SQL statements using the${var_name} syntax. You can also click SQL Preview to check the time variable's value.

Time formats

The following table describes the supported time format specifiers.

Specifier

Description

Example input

Example output

Era

G indicates the era.

Gyyyy

AD 2021

Year

  • y or yyyy: The year.

  • yy: The last two digits of the year.

  • Y: The week-numbering year, which is the year at the end of the week (Sunday).

yyyy

2021

Month

M: The month of the year. Valid values: [1,12]. MM: Zero-padded. Valid values: [01,12]. MMM returns the month name, such as "January" to "December".

MM

08

Week

  • w: The week of the year. Valid values: [1, 52]. ww: Zero-padded. Valid values: [01, 52].

  • W: The week of the month. Valid values: [1, 5].

ww

13

Day

  • D: The day of the year. Valid values: [1, 365]. DD: Zero-padded. Valid values: [01, 365]. DDD: Padded with two leading zeros. Valid values: [001, 365].

  • d: The day of the month. Valid values: [1, 31]. dd: Zero-padded. Valid values: [01, 31].

D

360

Day of week

  • E: The name of the day of the week, from Monday to Sunday.

  • e: The number of the day of the week. Valid values: [1, 7]. By default, 1 represents Monday.

    Note

    You can set the time offset to +1 day to align with calendars where 1 represents Sunday.

e

1

AM/PM

a: The AM/PM marker. Returns AM for times from 00:00 to 11:59, and PM for times from 12:00 to 23:59.

a

AM

Hour

  • H: The hour of the day (0-23). 0 represents midnight. Valid values: [0, 23]. HH: Zero-padded. Valid values: [00, 23].

  • h: The hour in AM/PM (1-12). 1 represents the first hour. Valid values: [1, 12]. hh: Zero-padded. Valid values: [01, 12].

  • K: The hour in AM/PM (0-11). 0 represents the first hour. Valid values: [0, 11]. KK: Zero-padded. Valid values: [00, 11].

  • k: The hour of the day (1-24). 1 represents the first hour. Valid values: [1, 24]. kk: Zero-padded. Valid values: [01, 24].

HH

10

Minute

m: The minute of the hour. Valid values: [0, 59]. mm: Zero-padded. Valid values: [00, 59].

m

27

Second

  • s: The second of the minute.

  • S: The millisecond.

ss

08

Time zone

z: The time zone.

z

UTC+08:00

Examples of combined time formats:

Example input

Example output

yyyy-MM-dd

2021-08-12

yyyyMM01

20210801

HH:mm:ss

11:05:21

yyyyMMdd HH:mm:ss

20210812 11:05:21

System variables

Variable name

Description

Example

sys.flow.start.timestamp

The run time's timestamp.

2021-05-24T11:20:07.562+08:00

sys.flow.start.year

The run time's year.

2021

sys.flow.start.month

The run time's month.

5

sys.flow.start.day

The run time's day.

24

sys.flow.start.hour

The run time's hour.

11

sys.flow.start.minute

The run time's minute.

20

sys.flow.start.second

The run time's second.

7

sys.flow.start.milliseconds

The run time's milliseconds.

562

sys.flow.start.timezone

The run time's time zone.

Asia/Shanghai

sys.flow.biztime

The data timestamp. By default, this is the run time minus one day.

1621740007562

sys.flow.name

The task flow name.

dwd_activity_daily_pv

sys.node.name

The node name.

Single Instance SQL-1

Status variables

Variable name

Description

all_success

All upstream tasks ran successfully.

all_failed

All upstream tasks failed.

one_success

At least one upstream task ran successfully.

one_failed

At least one upstream task failed.

Note

You can use status variables in a Conditional Branch node to control whether the task flow runs subsequent tasks based on a specific run status.