Create an offline compute template
Dataphin allows you to create offline compute templates. You can reference these templates when developing tasks to improve efficiency. This topic describes how to create, configure, and submit an offline compute template.
Background information
If multiple tasks have similar code logic but differ only in certain configurations or input parameters, you can encapsulate the code in an offline compute template and define the variable parts as template variables. This approach enables single-point maintenance and rapid code reuse, significantly improving task development efficiency.
Limitations
Only users with the super administrator, project administrator, or project developer role can create, configure, and submit offline compute templates.
To obtain the project administrator or project developer role, see Add project members.
Procedure
On the Dataphin homepage, choose Develop > Data Development in the top menu bar.
On the Develop page, select a project from the top menu bar. In Dev-Prod mode, you also need to select an environment.
In the left-side navigation pane, choose Data Processing > Compute Template. In the Compute Template list, click the
icon and select Offline Compute Template.In the Create offline compute template dialog box, configure the following parameters.
Parameter
Description
Template name
The name must meet the following rules:
It can contain uppercase letters, lowercase letters, digits, underscores (_), and hyphens (-).
It must be globally unique.
It cannot exceed 64 characters in length.
Node type
The available template types depend on the selected offline computing engine. Supported node types include Shell, Python, and Database SQL.
If you select Shell or Python as the node type, you can optionally configure a Python third-party package.
After you add a third-party module to a Python third-party package, you must reference the package in the task before you can import its modules. You can edit the referenced module in the Python third-party package settings within the compute task properties.
If you select Database SQL as the node type, you must also select a Database/Schema. If the data source type is Presto, you must also configure a Catalog after you configure the data source.
Select directory
The default directory is Offline Compute Template. You can also create a destination folder on the Compute Template page and select it as the directory. To create a new folder:
Above the compute template list, click the
icon to open the Create Folder dialog box.In the Create Folder dialog box, enter a folder Name, select Offline for Type, and then select a directory location as needed.
Click OK.
Description
Enter a brief description of the offline compute template, up to 1,000 characters.
Click OK to create the offline compute template.
On the code editor page for the offline compute template, write the template code.
You can define template variables by using the format
@@{variable_name}. A template variable name can contain only letters, digits, and underscores (_) and must start with a letter. For example:@@{variable}.
After editing the code, click the Debug button in the upper-left corner. In the Enter Parameters dialog box, enter the runtime value and click OK.
If the parameter type is a template parameter, the parameter value and runtime value display the default value. If no default value is set, a hyphen (-) is displayed. If parameter encryption is enabled for the property, the value is masked. If the parameter type is a local variable, the parameter value and runtime value are populated from the task parameter configuration. You can modify the runtime value, click Restore Defaults, or click Set to Null.
On the code editor page for the offline compute template, click Properties on the right side.
In the Properties panel, configure the parameters.
Parameter
Description
Basic information
Description
Enter a brief description of the offline compute template.
Python third-party package
Select the Python third-party packages to import. For more information, see Install Python Module.
NoteAfter you add a third-party module to a Python third-party package, you must reference the package in the task before you can import its modules.
Template parameters
Parameter description
Enter a description for each parameter to help other developers understand its purpose.
Default value
Set a default value for the parameter. This value can be overridden in tasks that reference the template. The new value takes effect when the task runs.
Parameter encryption
If you enable parameter encryption, the default value is encrypted to protect sensitive data. You cannot view the plaintext default value in tasks that reference this template. Dataphin decrypts the value at runtime.
If you disable parameter encryption, the configured default value is automatically cleared.
Task parameters
Parameter name
The name of the parameter defined in the code editor. The name can contain only digits, letters, and underscores (_) and cannot exceed 32 characters.
Parameter type
Parameter types include local variable and non-variable. For more information, see Variable classification.
To change multiple parameter types at once, select the parameters or click Select All, and then click Modify Parameter Type at the bottom of the list.
Parameter value
Local variable: The value can be up to 256 characters long or be set to null. If you need to enter a date or time, you can select or reference an expression from the list. For more information, see Variable assignment.
Non-variable: Cannot be defined.
Resource configuration
Scheduling resource group
Running scheduled tasks consumes scheduling resources. You can specify the scheduling resource group for each instance generated by tasks that reference the template. When an instance is scheduled, it consumes the resource quota of the specified resource group. If the group has insufficient available resources, the instance enters the Waiting for Scheduling Resources state. Resource groups isolate resources to ensure scheduling stability.
If you enable Shared Running Resources, you cannot specify a custom resource group. Tasks created from the template are shared-resource tasks. By default, these tasks use a shared scheduling resource pool. To modify the maximum concurrency limit for the shared resource pool, contact a meta-warehouse system administrator.
If you disable Shared Running Resources, you can specify a custom resource group. The resource group you select must be configured for Task Scheduling and associated with the task's project. For more information, see Resource group configuration.
ImportantFor tasks created from a template, you can configure the scheduling resource group only within the template.
If you select the project default resource group, the configuration automatically updates if the project's default resource group changes.
Click OK to save the offline compute template configuration.
On the code editor page for the offline compute template, click the Submit button at the top of the page. In the submission dialog box, enter comments.
Click OK and Submit.
After you edit a submitted Database SQL compute template, the following rules apply:
The system automatically checks whether the template code introduces new input tables. If no new input tables are introduced, the submission proceeds normally.
If your changes introduce new input tables, the submission fails if any downstream tasks are configured to Automatically use the latest version. Otherwise, the submission is allowed.
If the SQL code fails to parse, you can still submit it. However, the system displays a warning: The code cannot be parsed because it contains template variables. Modifying the template might introduce new input tables, which could break upstream dependencies for tasks that reference it. Proceed with caution.
Next steps
Create tasks based on the offline compute template you created. For more information, see the following topics: