When you edit a job, you can set time variable wildcards in the job parameters.
Variable wildcard format
E-MapReduce supports variable wildcards in the format of ${dateexpr-1d} or ${dateexpr-1h}. In these formats, dateexpr represents a standard time format expression. The following table describes the format specifiers.
Important The time format specifiers are case-sensitive.
| Format | Description |
| yyyy | The year as a four-digit number. |
| MM | The month as a two-digit number (01-12). |
| dd | The day of the month as a two-digit number (01-31). |
| HH | The hour in 24-hour format (00-23). Use hh for 12-hour format. |
| mm | The minute as a two-digit number (00-59). |
| ss | The second as a two-digit number (00-59). |
A time variable can be any combination of time specifiers that includes yyyy. You can use the plus (+) and minus (-) signs to specify a time offset. For example, if the variable ${yyyy-MM-dd} represents the current date:
- One day later: ${yyyyMMdd+1d} or ${yyyy-MM-dd hh:mm:ss+1d}.
- Three hours later: ${yyyyMMddHH+3h} or ${yyyy-MM-dd hh:mm:ss+3h}.
- Five days earlier: ${yyyyMMdd-5d} or ${yyyy-MM-dd hh:mm:ss-5d}.
For example, assume that the current time is 20160427 12:08:01:
- Entering ${yyyyMMdd HH:mm:ss-1d} in the job parameters resolves to 20160426 12:08:01 at runtime. This expression subtracts one day from the current time, maintaining precision to the second.
- The expression ${yyyyMMdd-1d} resolves to 20160426 at runtime, which represents the previous day.
- The expression ${yyyyMMdd} resolves to 20160427 at runtime, which represents the current date.
Note
- Currently, E-MapReduce supports offsets only for days and hours. This means the offset portion of the variable must use the format
+Nd,-Nd,+Nh, or-Nh, whereNis an integer. - A time variable parameter must start with
yyyy, such as ${yyyy-MM}. If you want to extract a specific time component, such as the month, use the following functions in the job content:parseDate(<parameter_name>, <time_format>): Converts the specified parameter to a Date object. <parameter_name> is the name of a variable that you set in the Configuration Parameters section. <time_format> is the time format that you used when you set the variable. For example, if you set a variable current_time = ${yyyyMMddHHmmss-1d}, the time format must be set toyyyyMMddHHmmss.formatDate(<Date_object>, <time_format>): Formats a Date object into a time string.
Examples:- Get the hour literal from the
current_timevariable: ${formatDate(parseDate(current_time, 'yyyyMMddHHmmss'), 'HH')} - Get the year literal from the
current_timevariable: ${formatDate(parseDate(current_time, 'yyyyMMddHHmmss'), 'yyyy')}
Procedure
-
Go to the Projects page in Data Platform.
-
Log in to the E-MapReduce console with your Alibaba Cloud account.
-
In the top navigation bar, select the region and resource group.
-
Click the Data Development tab.
-
- On the Projects page, locate the desired project and click Edit Job in the Actions column.
- Configure job settings.
- On the Edit Job page, select the desired job, and then click Job Settings in the upper-right corner.
- In the Configuration parameters section, click the
icon to add a parameter, and then set the parameter using the variable wildcard format.
For example, if you add a parameter nameddy_date, you can reference this parameter in the job content as${dy_date}, such as--hiveconf date=${dy_date}.The parameter can now be referenced in your job content.