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
Category | Concept Name | Meaning | Illustration |
---|---|---|---|
Parameter Definition | Custom Parameter | Refers to the parameters that users define and reference in the code. The format is fixed as ${custom parameter name} | ${my_param} |
Parameter Assignment | Constant | Refers to fixed values, such as strings and numbers, used to assign values to custom parameters | abcd or 1234 |
Parameter Assignment | System Built-in Parameter | Refers 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 instance | sys_plan_datetime |
Parameter Assignment | System Built-in Time Function | Refers to a series of function expressions built into the system for some common time conversion calculations | add_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:
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 Name | Parameter Value |
---|---|
city | Shanghai |
time | $[yyyy-MM-dd HH:mm:ss] |
lastDay | add_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:
Supported Built-in Parameters
The system supports the following built-in parameters:
Parameter Name | Description | Example |
---|---|---|
bizdate | Format is yyyyMMdd | Assuming the reference time is 2023-09-22 18:00:00 bizdate is replaced with 20230921 |
sys_biz_day | Business date, one day less than the planned time, format is yyyy-MM-dd | Assuming the reference time is 2023-09-22 18:00:00 sys_biz_day is replaced with 2023-09-21 |
sys_biz_datetime | Business time, one day less than the planned time, format is yyyy-MM-dd HH:mm:ss | Assuming the reference time is 2023-09-22 18:00:00 sys_biz_datetime is replaced with 2023-09-21 18:00:00 |
sys_plan_day | Planned date, format is yyyy-MM-dd | Assuming the reference time is 2023-09-22 18:00:00 sys_plan_day is replaced with 2023-09-22 |
sys_plan_datetime | Planned time, format is yyyy-MM-dd HH:mm:ss | Assuming the reference time is 2023-09-22 18:00:00 sys_plan_datetime is replaced with 2023-09-22 18:00:00 |
sys_plan_timestamp | Planned timestamp, Linux 13-digit timestamp, to milliseconds | Assuming the reference time is 2023-09-22 18:00:00 sys_plan_timestamp is replaced with 1695463200000 |
sys_task_id | Task ID Note: Only supported during task scheduling | Assuming the task ID is 1002 sys_task_id is replaced with 1002 |
sys_task_name | Task name Note: Only supported during task scheduling | Assuming the task name is demo_task sys_task_name is replaced with demo_task |
sys_task_owner | Task owner Note: Only supported during task scheduling | Assuming 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
Expression | Description | Example |
---|---|---|
yyyy | Four-digit year | 2023 |
yy | Two-digit year | 23 |
MM | Two-digit month | 09 |
dd | Two-digit day | 22 |
HH | Hour | 18 |
mm | Minute | 59 |
ss | Second | 49 |
.SSS | Milliseconds | 377 |
ZZ | Time 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 Amount | Unit (Abbreviation) | Unit (Full Name) | Description | Example |
---|---|---|---|---|
Integer, using positive or negative values to indicate increase or decrease | ms | milli/millisecond | Millisecond | 400ms |
s | sec/second | Second | 400s | |
m | min/minute | Minute | 3m | |
h | hour | Hour | 1h | |
d | day | Day | 2d | |
mon | month | Month | 1mon | |
y | year | Year | -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 Function | Return Value | Description | Example |
---|---|---|---|
timestamp() | Timestamp | The timestamp of the current scheduled time | timestamp() |
day_of_week(String duration) | Day of the week | The calculated date's day of the week, for example, returning 1 means the first day | day_of_week('-1d')] /$[day_of_week()] |
last_day_of_month(String format,String duration) | Time format string of the last day of the month | The last day of the month of the calculated date, the format is returned according to the passed format, default is yyyy-MM-dd | last_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 week | The last day of the week of the calculated date, the format is returned according to the passed format, default is yyyy-MM-dd | last_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:
- Write SQL
-
Execute the code to assign the value to
lastDay
asadd_days('yyyy-MM-dd', -1)
-
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.