This topic demonstrates how to create a scheduled task in Data Studio by using a MaxCompute job as an example. This guide helps you quickly get started with the basic features of Data Studio.
Prerequisites
-
You have bound the required data source. For more information, see Preparations: Bind a compute engine or a cluster.
-
You have the permissions of the Development role. For more information about how to grant permissions, see Add members to a workspace and manage their roles.
This topic uses an ODPS SQL node as an example. Therefore, the workspace must be bound to a MaxCompute data source.
Background
DataWorks Data Studio provides a visual development interface for various compute engines, such as MaxCompute, Hologres, EMR, and CDH. It supports intelligent code development, data cleansing, data processing, and standardized task deployment, ensuring efficient and stable data development. For more information, see Data Studio (legacy).
Typically, the process of writing raw business data to DataWorks and processing it into a final result table includes the following steps:
-
Create multiple data tables in DataWorks. For example:
-
A source table to store data synchronized from other data sources.
-
A result table to store data that has been cleansed and processed by DataWorks.
-
-
Create a synchronization task to sync business data to the source table.
-
Create a compute node to cleanse and process the data from the source table in layers and write the result of each layer to the corresponding result table.
Alternatively, after you create a table, you can upload local data directly to the source table in DataWorks. You can then use a compute node to cleanse and process the data and store the results in the result table. This topic's example involves uploading local data and cleansing it with a compute node.
Go to Data Studio
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.
Procedure
-
Data development is organized around workflows. You must create a workflow before you can begin developing code.
-
DataWorks allows you to create tables visually, which are then displayed in a directory structure. Before you begin data development, you must create a table in the compute engine to store data cleansing results.
-
DataWorks encapsulates tasks from different compute engines into different node types. You can select the appropriate node type based on your business needs.
-
On the node editing page, write your business logic using the syntax of the node's database engine.
-
Step 5: Configure schedule settings for the node.
Define the scheduling properties for the node to run it periodically.
-
DataWorks provides three methods to debug your code and verify its logic: Quick run for code snippets, Run, and Advanced run.
-
Step 7: Save and submit the node.
After you debug the node, you must save and submit it.
-
To ensure that production tasks run efficiently and to avoid wasting compute resources, run smoke testing on your task in the development environment to verify its correctness before deployment.
-
DataWorks only runs scheduled tasks that are deployed to the production environment. After the smoke testing is successful, you must deploy the task to the production scheduling system.
Step 1: Create a workflow
DataWorks organizes data development around workflows. Workflows use container-like panels for development nodes, grouping related tools, optimizations, and management actions around a central object. This approach simplifies development and management. You can group related business tasks into a single workflow to meet your requirements.
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.
-
Create a workflow.
You can create a workflow in one of the following two ways:
-
Method 1: Hover over the
icon and click Create Workflow. -
Method 2: In the left-side navigation tree of Data Studio, right-click Workflow and select Create Workflow.
-
-
Enter a name and description for the workflow and click Create.
This tutorial creates a workflow named
Create your first scheduled task. In a real-world scenario, you should plan your workflows based on your business requirements.NoteFor more information about workflows, see Create and manage workflows.
Step 2: Create tables
Data Studio nodes cleanse and process your source data. Therefore, you must first create tables in the compute engine to store the data cleansing results and define the table structure.
-
Create the tables.
-
In the workflow you created in Step 1, expand the sub-directory, right-click , and select Create Table.
-
Configure the table name, engine instance, and other information.
In this tutorial, the following two tables are created.
Table name
Description
bank_dataStores raw business data.
result_tableStores the cleansed data results.
Note-
For the table creation statements, see Table creation statements.
-
For more information about visually creating tables for various engines, such as creating MaxCompute or EMR tables, see Create a table.
-
-
Configure the table structure.
Go to the table editing page, switch to DDL mode, and use DDL statements to configure the table structure. After the table structure is generated, enter a Display Name for the table in the General section. Then, submit it to both the development environment and the production environment. After you submit the table, you can view it in the data source project of the corresponding environment. To view the bound data source information for each environment, see Bind MaxCompute compute resources.
Note-
Table operations such as creation and updates take effect in the compute engine only after you submit them to the corresponding environment.
-
You can also configure the table structure visually based on your business needs and on-screen instructions. For more information about visually creating tables, see Create and use MaxCompute tables.
The following statement is a reference for generating the
bank_datatable structure.CREATE TABLE IF NOT EXISTS bank_data ( age BIGINT COMMENT 'Age', job STRING COMMENT 'Job type', marital STRING COMMENT 'Marital status', education STRING COMMENT 'Education level', default STRING COMMENT 'Whether the user has a credit card', housing STRING COMMENT 'Housing loan', loan STRING COMMENT 'Personal loan', contact STRING COMMENT 'Contact method', month STRING COMMENT 'Month of the year', day_of_week STRING COMMENT 'Day of the week', duration STRING COMMENT 'Last contact duration, in seconds', campaign BIGINT COMMENT 'Number of contacts performed during this campaign', pdays DOUBLE COMMENT 'Days since the last contact from a previous campaign', previous DOUBLE COMMENT 'Number of contacts performed before this campaign', poutcome STRING COMMENT 'Outcome of the previous marketing campaign', emp_var_rate DOUBLE COMMENT 'Employment variation rate', cons_price_idx DOUBLE COMMENT 'Consumer price index', cons_conf_idx DOUBLE COMMENT 'Consumer confidence index', euribor3m DOUBLE COMMENT 'Euribor 3-month rate', nr_employed DOUBLE COMMENT 'Number of employees', y BIGINT COMMENT 'Whether the client has subscribed to a term deposit' );The following statement is a reference for generating the
result_tabletable structure.CREATE TABLE IF NOT EXISTS result_table ( education STRING COMMENT 'Education level', num BIGINT COMMENT 'Number of people' ) PARTITIONED BY ( day STRING, hour STRING ); -
-
Upload data.
Store your raw business data in a DataWorks table. In this example, the local file banking.txt is uploaded to the
bank_datatable in DataWorks to simulate a real-world data write scenario. In the data import wizard, first select the target table bank_data, confirm that the table schema includes fields such as age, job, marital, education, default, and housing, and then set the partition parameters. Then, upload the local file banking.txt, set the file format to CSV, the delimiter to a comma, the character set to GBK, and the import start row to 1, and select the 'First row is header' checkbox. Finally, select Match by Name as the field mapping method, confirm that the mapping between the source and target fields is correct, and then click Import Data to complete the operation. For more information about uploading data, see Upload local data to the bank_data table.
Step 3: Create a node
Select an appropriate node type for development based on your business requirements.
DataWorks nodes are categorized as data synchronization nodes and compute nodes. In a typical development process, you first use a batch synchronization task to sync data from business databases to a data warehouse. Then, you use DataWorks compute nodes to cleanse and process the table data in the warehouse.
-
Create a node.
You can create a node in one of the following two ways:
-
Method 1: Create from the navigation tree.
-
In the navigation tree, find the workflow you created in Step 1 under Workflow.
-
Right-click the desired engine and select an appropriate node under Create Node.
-
-
Method 2: Create from the workflow panel.
-
In the navigation tree, find the workflow you created in Step 1 under Workflow.
-
Double-click the workflow to open its panel.
-
In the left-side navigation pane of the panel, click the desired node or drag it onto the canvas.
-
-
-
Configure the node's engine instance, name, and other settings.
This tutorial creates an ODPS SQL node named
result_table, which is the same as the name of the result table created in Step 2.NoteWhen you use DataWorks nodes for data development, you cleanse data with a development node and store the results in a result table. Name the node after the result table it populates to make it easier to locate the table data produced by the node.
In the Common Nodes section of the Data Studio panel, drag the ODPS SQL node onto the canvas on the right to create it.
Step 4: Edit the node
Find the node you created in Step 3 in the workflow navigation tree or on the workflow panel. Double-click the node to open the editor. Based on the node type, write your business logic using the syntax of the corresponding database.
In this tutorial, the result_table node writes data from a specific partition of the bank_data table to the corresponding partition of the result_table table. The target partition is defined using the variables day and hour.
-
During code development, if you need to dynamically replace parameters in a scheduling context, you can define variables in your code using the format
${your_variable_name}. You can then assign a value to this variable when you configure the schedule settings in Step 5. -
For more information about scheduling parameters, see Supported formats for scheduling parameters.
-
For more information about the development syntax for different node types, see Create and use nodes.
--@exclude_output=xc_DPE_E2.result_table
--@exclude_input=bank_data
--odps sql
--***********************************************************--
--author:xxx
--create time:2022-08-11 14:33:23
--***********************************************************--
INSERT OVERWRITE TABLE result_table partition (day='${day}', hour='${hour}')
SELECT education
, COUNT(marital) AS num
FROM bank_data
WHERE day='${day}' and hour='${hour}'
GROUP BY education;
The following code is provided for your reference.
INSERT OVERWRITE TABLE result_table partition (day='${day}', hour='${hour}')
SELECT education
, COUNT(marital) AS num
FROM bank_data
GROUP BY education;
Step 5: Configure schedule settings
Configure the scheduling properties to run the node periodically. On the node editor page, click Scheduling in the right-side navigation pane and configure the properties based on your business requirements.
|
Parameter |
Description |
|
DataWorks automatically displays the node's name, ID, type, and owner. These properties do not require separate configuration. Note
|
|
|
Define the parameters used for node scheduling. DataWorks provides built-in and custom parameters for dynamic parameter assignment during task scheduling. If you defined variables in the code in Step 4, you can assign values to them here. This tutorial assigns values to the variables from Step 4 to write hourly data from the
After you configure these settings in the Parameters section of the Scheduling pane, the values assigned to |
|
|
The time properties define how and when the node runs. Use these settings to configure periodic instance generation, scheduling cycle, execution time, rerun support, and the timeout period for automatic task termination. Note
In this tutorial, the |
|
|
Configure the scheduling resource group to be used when the task is deployed to the production environment for scheduling. This tutorial uses the default serverless resource group provided when DataWorks was activated. For more information, see Use a serverless resource group. |
|
|
Define the upstream and downstream dependencies for node scheduling. Set dependencies based on data lineage. This ensures that the current node only runs after the upstream tasks that produce its required data have completed successfully, allowing it to query the upstream table data correctly. Note
In this tutorial, assume that a task outside the current workflow produces the |
|
|
Defines how parameters are passed between upstream and downstream nodes. A downstream node can use this feature to retrieve values from an upstream node. Note
This feature is typically used with assignment nodes or assignment parameters.
|
Step 6: Debug the code
You can use the following methods to debug your code logic and ensure it is correct.
|
Method |
Description |
Recommendation |
|
Quickly runs a selected code snippet. |
Use this method when you need to quickly run a piece of code. |
|
|
Toolbar: Run ( |
Assigns constant values to variables for a test run. Note
The first time you click Run on a new node, you must manually assign constant values to the code variables in the dialog box. This assignment is saved and does not need to be repeated for subsequent runs. |
Use this method if you need to frequently debug the entire code. |
|
Toolbar: Advanced Run ( |
Requires you to assign constant values to variables for each test run. |
Use this method if you need to change the variable assignments for a test run. |
This tutorial uses Advanced run to test the results of the run for 2022.09.07 14:00. In the Parameters dialog box, select a Scheduling Resource Group (for example, Public Scheduling Resource Group). In the Custom Parameters section, set the parameter values (for example, day=20220907 and hour=14). Click OK to execute the code. The run log shows that the execution was successful.
Step 7: Save and submit the node
After you have configured and tested the node, you must save the configuration and submit the node to the development environment.
You can submit the node only after you have configured the Rerun attribute and Parent Nodes in Step 5.
-
Click the
icon on the toolbar to save the node configuration. -
Click the
icon on the toolbar to submit the node to the development environment.
Step 8: Run smoke testing
Perform smoke testing before deploying a task to ensure that production tasks run efficiently and to avoid wasting compute resources. Smoke testing runs in the development environment, so you must first submit the node to that environment. After submission:
-
Click the
icon in the toolbar and configure the business date in the smoke testing dialog box. -
After the smoke test is complete, click the
icon in the toolbar to view the test results.
This tutorial tests whether the scheduling parameter configuration meets expectations. The result_table node is scheduled to run every hour from 00:00 to 23:59. Therefore, the configuration in the following figure will generate two hourly instances, with scheduled run times of 00:00 and 01:00 respectively.
-
An instance is a snapshot of a task that is generated when a periodic task runs according to its schedule.
-
Because the
result_tablenode is set as an hourly task, you must not only configure the business date for smoke testing but also select the time range of instances to run. -
For more information about smoke testing, see Run smoke testing.
Click the Smoke testing (☑) icon in the top toolbar. In the smoke testing panel that appears, set the Business Date (for example, 2022-09-01), Start Time (00:00), and End Time (01:00).
Step 9: Deploy the task
In a basic mode workspace, tasks are scheduled periodically after submission. In a standard mode workspace, a submitted task enters a "to be deployed" state. You must then deploy the task to the production environment to enable periodic scheduling.
-
DataWorks only supports automatic scheduling for tasks that are deployed to the production environment. After the smoke testing is successful, you must deploy the task to the production scheduling system to enable periodic scheduling.
-
For more information about the differences between workspace modes, see Differences between workspace modes.
In a standard mode workspace, any changes you submit in Data Studio, such as creating, updating, or deleting nodes, resources, and functions, are sent to the task deployment page to await deployment. To apply these changes, you must navigate to and create a deployment package to release them to the production environment. The changes become active only after a successful deployment. For more information, see Deploy tasks.
The following table describes the deployment process.
|
Deployment topic |
Description |
|
Deployment process control |
Role permissions and process controls constrain deployment operations. After you perform a deployment, ensure that the status of the deployment package is "successful." Note
|
|
Deployment effective time control |
For deployments performed during the daily instance generation window ( Note
This restriction affects both the Next Day and Immediately After Deployment instance generation modes. For more information about these modes, see Instance generation modes. |
Next steps
You can go to to view the batch scheduling tasks deployed to the production environment and perform related O&M operations. For more information, see Basic O&M for periodic tasks.