All Products
Search
Document Center

DataWorks:Overview of a script template

Last Updated:Sep 19, 2023

A script template defines an SQL code process that includes multiple input and output parameters. You can introduce one or more source tables to an SQL code process and use the SQL code process to filter source table data, join source tables, and aggregate data to generate an output table required for business. This topic provides an overview of a script template.

Overview

In actual business scenarios, a large number of SQL code processes are similar. The input tables or output tables of these processes may have the same schema or compatible data types but different table names. In this case, developers can abstract an SQL code process as a script template to reuse the SQL code. The script template extracts input parameters from input tables and output parameters from output tables.

When you create an SQL Snippet node, you need to only select an existing script template from the script template list based on your business process and configure specific parameters for input tables and output tables in your business for the selected script template. This way, you do not need to repeatedly edit the code. This helps prevent repeated operations during development and improve development efficiency. You can deploy and run a created SQL Snippet node in the same manner in which you deploy and run other SQL nodes.

Permissions

To create and use a script template, you must be assigned the Development role. For information about how to assign a role, see Add a RAM user to a workspace as a member and assign roles to the member.

Script template types

Script templates are classified into workspace-level and public script templates. You can specify the type of a script template when you create the script template.

  • Workspace-level script template: After this type of script template is deployed, only the members in the current DataWorks workspace can use this type of script template. To use this type of script template, you must be a member in the current DataWorks workspace. For more information, see Add a RAM user to a workspace as a member and assign roles to the member.

  • Public script template: The developers of this type of script template can go to the Public tab and make a general-purpose script template public to the current tenant. This way, all users within the current tenant can use the script template.

Use a script template

Script templates that are created in DataWorks must work together with SQL Snippet nodes.

  1. Define a script template.

    In the Snippets pane of DataStudio, developers can abstract an SQL code process and define input and output parameters. This way, the SQL code process can process a specified input table based on input parameters to generate an output table with business value based on output parameters. The input and output parameters are configured in the @@{Parameter name} format.

    • The following types of input parameters are supported:

      • Table: Use this type of input parameters if output results are of a single type.

      • String: Use this type of input parameters if the values of input parameters are controlled based on variables.

    • The type of an output parameter must be Table.

  2. Reference a script template.

    On the DataStudio page, you can create an SQL Snippet node to reference the desired script template and replace input and output parameters in the script template to reuse code.

Manage script templates

You can perform operations, such as sharing a script template, upgrading a script template, and viewing reference records of a script template, based on your business requirements. This helps maintain script templates and improve execution efficiency of script templates. For more information, see Share a script template and view the reference records of a script template and Upgrade a script template.