Configure code templates
A code template defines the default content that populates the code editor when you create a node. It includes information like the node type, creator, and creation time to help you identify and manage nodes. This topic describes the code template types supported by DataWorks and how to configure code templates.
Limitation
Only a Workspace Administrator can modify code templates. To allow other users to do so, grant them the Workspace Administrator role. For more information, see Add a RAM user to a workspace as a member and assign roles to the member.
Configure a code template
Go to the Template Management tab.
Log on to the DataWorks console. In the target region, click in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Data Development.
At the bottom of the left-side navigation pane, click the
icon to open the Configure page.On the Configure page, click the Node Template tab to go to the Node Template page.
Configure the code template.
On the Node Template page, click Modify next to the desired Template to modify the code template for that node type. After you save the template, it applies to all new nodes of that type created in Data Studio. For information about the template types that DataWorks supports, see Supported code template types.
The following code provides an example of a code template for an ODPS SQL node.
--odps sql --********************************************************** --author: xxx --create time:2023-06-26 11:33:05 --**********************************************************
Supported code template types
You can use the following variables in a code template to record information about new nodes:
author: Records the node creator.createTime: Records the node creation time.
The following table describes the node types supported by DataWorks and the default code templates provided for each node type.
Engine type | Node type | Default template |
MaxCompute | The default ODPS Script code template contains the comment lines | |
In the Code Template dialog, the default template contains the | ||
The default code template for this node type contains | ||
The default PyODPS 2 code template contains a tip that advises against downloading large amounts of data from MaxCompute by using methods such as | ||
The default PyODPS 3 code template contains a tip that advises against downloading large amounts of data from MaxCompute. Related methods include | ||
EMR | The code template for EMR MR nodes contains the variable placeholders | |
The code template dialog displays the default template, which contains the comment lines | ||
The EMR Presto code template contains the placeholder variables | ||
The default code template for EMR Spark Streaming nodes contains the comment lines | ||
EMR Trino | The default EMR Trino code template contains the comment lines | |
The default code template for EMR Hive nodes contains the author ( | ||
The default code template for EMR Spark nodes contains the author ( | ||
The default code template for EMR Spark SQL nodes contains the template variables | ||
The EMR Impala code template contains comment header information: the author placeholder variable | ||
CDH | CDH Hive | The CDH Hive code template contains the template variables |
CDH Spark | The CDH Spark code template contains a comment header that defines the template variables | |
CDH MR | The code template contains the comment header | |
CDH Presto | The CDH Presto code template contains the comment lines | |
CDH Impala | The CDH Impala code template contains the variables | |
Hologres | The default Hologres SQL code template contains the comment lines | |
Others | The Shell code template contains the | |
The code template contains a SQL comment header with the placeholders | ||
The default code template for HTTP Trigger contains the following comments: the |