Configure code templates

Updated at:

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

  1. Go to the Template Management tab.

    1. Log on to the DataWorks console. In the target region, click Data Development and O&M > Data Development in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Data Development.

    2. At the bottom of the left-side navigation pane, click the Settings icon to open the Configure page.

    3. On the Configure page, click the Node Template tab to go to the Node Template page.

  2. 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

ODPS Script

The default ODPS Script code template contains the comment lines --author:${author} and --create time:${createTime} as variable placeholders to automatically populate the author name and creation time. In the Code Template dialog, edit the template and click Save.

ODPS SQL

In the Code Template dialog, the default template contains the --odps sql identifier line and the template variables --author:${author} and --create time:${createTime}. After you edit the template, click Save.

ODPS MR

The default code template for this node type contains -odps mr, -author:${author}, and -create time:${createTime} as variable information. After you edit the template, click Save to apply the changes.

PyODPS 2

The default PyODPS 2 code template contains a tip that advises against downloading large amounts of data from MaxCompute by using methods such as open_reader and to_pandas. It recommends using PyODPS DataFrame or MaxCompute SQL for data processing. Reference: https://developer.aliyun.com/article/745029. Click Save to save the template.

PyODPS 3

The default PyODPS 3 code template contains a tip that advises against downloading large amounts of data from MaxCompute. Related methods include open_reader for tables or instances and to_pandas for DataFrames. It recommends using PyODPS DataFrame created from MaxCompute tables or MaxCompute SQL directly. Reference: https://developer.aliyun.com/article/745029.

EMR

EMR MR

The code template for EMR MR nodes contains the variable placeholders --author:${author} and --create time:${createTime}, along with the note EMR MR node can only run on exclusive resource groups.. After you edit the template, click Save.

EMR Shell

The code template dialog displays the default template, which contains the comment lines --author:${author} and --create time:${createTime}, along with the note EMR Shell node can only run on exclusive resource groups.. After you edit the template, click Save or Cancel.

EMR Presto

The EMR Presto code template contains the placeholder variables ${author} (author) and ${createTime} (creation time), along with the note that EMR Presto nodes can only run on exclusive resource groups. Click Save to save the template.

EMR Spark Streaming

The default code template for EMR Spark Streaming nodes contains the comment lines --author:${author} and --create time:${createTime}, along with the note --EMR Spark Streaming node can only run on exclusive resource groups.. After you edit the template, click Save.

EMR Trino

The default EMR Trino code template contains the comment lines --author:${author} and --create time:${createTime} as variable placeholders, along with the note --EMR Trino node can only run on exclusive resource groups.. After you edit the template, click Save.

EMR Hive

The default code template for EMR Hive nodes contains the author (${author}) and creation time (${createTime}) parameters, along with the note that EMR Hive nodes can only run on exclusive resource groups. After you edit the template, click Save.

EMR Spark

The default code template for EMR Spark nodes contains the author (${author}) and creation time (${createTime}) variables, along with the note that EMR Spark nodes can only run on exclusive resource groups.

EMR Spark SQL

The default code template for EMR Spark SQL nodes contains the template variables --author:${author} and --create time:${createTime}, along with the note that EMR Spark SQL nodes can only run on exclusive resource groups. In the Code Template dialog, edit the template and click Save to apply the changes.

EMR Impala

The EMR Impala code template contains comment header information: the author placeholder variable ${author}, the creation time placeholder variable ${createTime}, and the note EMR Impala node can only run on exclusive resource groups..

CDH

CDH Hive

The CDH Hive code template contains the template variables --author:${author} and --create time:${createTime}, along with the note that CDH Hive nodes can only run on exclusive resource groups. In the dialog, edit the template and click Save to complete the configuration.

CDH Spark

The CDH Spark code template contains a comment header that defines the template variables --author:${author} and --create time:${createTime}, along with the note CDH Spark node can only run on exclusive resource groups.. After you edit the template, click Save.

CDH MR

The code template contains the comment header --CDH MR, the variable placeholders --author:${author} and --create time:${createTime}, and the note --CDH MR node can only run on exclusive resource groups..

CDH Presto

The CDH Presto code template contains the comment lines --author:${author} and --create time:${createTime}, along with the note CDH Presto node can only run on exclusive resource groups..

CDH Impala

The CDH Impala code template contains the variables --author:${author} and --create time:${createTime}, along with the note CDH Impala node can only run on exclusive resource groups.. In the dialog, edit the template and click Save.

Hologres

Hologres SQL

The default Hologres SQL code template contains the comment lines --author:${author} and --create time:${createTime} as variable placeholders. After you edit the template, click Save.

Others

Shell

The Shell code template contains the #!/bin/bash declaration line and the two variable placeholders ${author} (author) and ${createTime} (creation time). After you edit the template, click Save.

ClickHouse SQL

The code template contains a SQL comment header with the placeholders --author:${author} and --create time:${createTime}. After you edit the template, click Save.

HTTP Trigger

The default code template for HTTP Trigger contains the following comments: the --HTTP Trigger header line, the two variable placeholder lines --author:${author} and --create time:${createTime}, and a description stating that HTTP Trigger is a virtual node that triggers its downstream nodes by calling the DataWorks OpenAPI RunTriggerNode operation. It is typically used to integrate with your own systems. For more information, see HTTP Trigger.