Task Parameters

Task parameters can be used for dynamic value replacement during the actual execution of the task.

Special note: This feature is currently in the grayscale stage, and the complete parameter functionality is only available to some customers. You can use the method at the end of the document to verify if it is supported.

Basic Concepts

CategoryConcept NameMeaningIllustration
Parameter DefinitionCustom ParameterRefers to the parameters that users define and reference in the code. The format is fixed as ${custom parameter name}${my_param}
Parameter AssignmentConstantRefers to fixed values, such as strings and numbers, used to assign values to custom parametersabcd or 1234
Parameter AssignmentSystem Built-in ParameterRefers to a series of parameter expressions built into the system to facilitate users in obtaining dynamic information that needs to be calculated, such as the scheduled time of a task instancesys_plan_datetime
Parameter AssignmentSystem Built-in Time FunctionRefers to a series of function expressions built into the system for some common time conversion calculationsadd_months(yyyy-MM-dd HH:mm:ss,N)

Parameter Reference and Assignment

  • In all task types, the ${} placeholder is used to mark the position as a variable parameter that needs to be replaced. The replacement only replaces the value of the corresponding placeholder.

    • Assume the value of the dt parameter is 2023-09-22
    • The code is written as follows: where pt=${dt}, the code will be replaced with where pt=2023-09-22
    • The code is written as follows: where pt='${dt}', the code will be replaced with where pt='2023-09-22'
  • Assigning values to user-defined parameters can be done in two ways: constants and variables

    • Constant: Direct input, no decoration needed
    • Variable: Includes system built-in parameters and system built-in time functions, directly use the name

Parameter Usage Example

Taking a Lakehouse SQL task as an example, write the following code in the data development interface:

SELECT
  table1.*
FROM
  table1
WHERE
  city = '${city}'
  AND t = '${time}'
  AND bizdate = '${lastDay}';

In the above code example, the system will recognize three parameters: city, lastDay, and format. During actual execution, values can be assigned to them, for example:

Parameter NameParameter Value
cityShanghai
time$[yyyy-MM-dd HH:mm:ss]
lastDayadd_days('yyyy-MM-dd', -1)

Assuming the task's trigger execution time is 2023-09-20 18:00:00, after assigning and replacing the parameters, the following code will be executed:

SELECT
  table1.*
FROM
  table1
WHERE
  city = 'Shanghai'
  AND t = '2023-09-20 18:00:00'
  AND bizdate = '2023-09-19';

Supported Built-in Parameters

The system supports the following built-in parameters:

Parameter NameDescriptionExample
bizdateFormat is yyyyMMddAssuming the reference time is 2023-09-22 18:00:00 bizdate is replaced with 20230921
sys_biz_dayBusiness date, one day less than the planned time, format is yyyy-MM-ddAssuming the reference time is 2023-09-22 18:00:00 sys_biz_day is replaced with 2023-09-21
sys_biz_datetimeBusiness time, one day less than the planned time, format is yyyy-MM-dd HH:mm:ssAssuming the reference time is 2023-09-22 18:00:00 sys_biz_datetime is replaced with 2023-09-21 18:00:00
sys_plan_dayPlanned date, format is yyyy-MM-ddAssuming the reference time is 2023-09-22 18:00:00 sys_plan_day is replaced with 2023-09-22
sys_plan_datetimePlanned time, format is yyyy-MM-dd HH:mm:ssAssuming the reference time is 2023-09-22 18:00:00 sys_plan_datetime is replaced with 2023-09-22 18:00:00
sys_plan_timestampPlanned timestamp, Linux 13-digit timestamp, to millisecondsAssuming the reference time is 2023-09-22 18:00:00 sys_plan_timestamp is replaced with 1695463200000
sys_task_idTask ID Note: Only supported during task schedulingAssuming the task ID is 1002 sys_task_id is replaced with 1002
sys_task_nameTask name Note: Only supported during task schedulingAssuming the task name is demo_task sys_task_name is replaced with demo_task
sys_task_ownerTask owner Note: Only supported during task schedulingAssuming the task owner is UAT_TEST sys_task_owner is replaced with UAT_TEST

Built-in system parameters can be directly used when assigning values to user-defined parameters. As shown below, in the code, you can directly write ${param} to reference the parameter. When assigning a value to param, you can use sys_plan_day as the right value.

Supported Built-in Time Expressions

The system supports built-in time expressions, primarily various time processing functions, such as the commonly used yyyyMMdd combinations. Time function expressions refer to the ISO-8601 standard and are case-sensitive.

Time Expressions

ExpressionDescriptionExample
yyyyFour-digit year2023
yyTwo-digit year23
MMTwo-digit month09
ddTwo-digit day22
HHHour18
mmMinute59
ssSecond49
.SSSMilliseconds377
ZZTime zone+08:00
Usage: $[Time Expression]

Examples of the above combinations: $[yyyy-MM-dd], $[yyyy-MM-dd HH:mm:ss], $[yyyy-MM-dd HH:mm:ss.SSSZZ], $[yyyyMMddHHmmss], $[HHmmss], $[MM], etc. Each element is the smallest unit, combined in the corresponding order, such as direct concatenation, separated by -, separated by /, etc.

Time Expression Increments and Decrements

To meet the needs of increasing or decreasing the corresponding time, the system supports time increments and decrements, defined as follows:

Offset AmountUnit (Abbreviation)Unit (Full Name)DescriptionExample
Integer, using positive or negative values to indicate increase or decreasemsmilli/millisecondMillisecond400ms
ssec/secondSecond400s
mmin/minuteMinute3m
hhourHour1h
ddayDay2d
monmonthMonth1mon
yyearYear-1y
Usage: $[Time Expression, Increment/Decrement]

Similar to the usage of time expressions, a second parameter needs to be passed in to indicate the amount and unit to be increased or decreased, separated by a comma in English after the expression. For example: $['yyyy-MM-dd HH','-1d'] means subtract one day, $['yyyy-MM-dd HH','-1h'] means subtract one hour, $['yyyy-MM-dd HH','1h'] means add one hour, and so on.

Supported Built-in Time Functions

In addition to time expressions, the system also supports complex calculations based on time, known as built-in time functions. The list is as follows:

Time FunctionReturn ValueDescriptionExample
timestamp()TimestampThe timestamp of the current scheduled timetimestamp()
day_of_week(String duration)Day of the weekThe calculated date's day of the week, for example, returning 1 means the first dayday_of_week('-1d')] /$[day_of_week()]
last_day_of_month(String format,String duration)Time format string of the last day of the monthThe last day of the month of the calculated date, the format is returned according to the passed format, default is yyyy-MM-ddlast_day_of_month() /last_day_of_month('yyyy-MM-dd','-1mon')
last_day_of_week(String format,String duration)Time format string of the last day of the weekThe last day of the week of the calculated date, the format is returned according to the passed format, default is yyyy-MM-ddlast_day_of_week() /last_day_of_week('yyyy-MM-dd','-1w')

Verify if full parameter functionality is supported

As mentioned above, task parameters are open in grayscale, you can use the following methods to verify if they are supported:

  1. Write SQL
SELECT '${lastDay}';
  1. Execute the code to assign the value to lastDay as add_days('yyyy-MM-dd', -1)

  2. Check if the parameter replacement and task execution return results are normal. If normal (assuming the current date is 2023-11-12, the return value is 2023-11-11), it indicates that it is within the grayscale range and supports the full parameter functionality; otherwise, it indicates that it is not supported.