This topic describes how to develop a task by using a Db2 node.
Background
Db2 is a relational database management system (RDBMS) used to store, retrieve, and manage data. It is suitable for processing complex queries and transactions for high-throughput workloads, large datasets, and data warehouses. For more information, visit the official Db2 website.
Prerequisites
A workflow must be created.
In DataStudio, you perform development operations for different compute engines within a workflow. Therefore, you must create a workflow before you create a node. For more information, see Create a workflow.
-
A Db2 data source has been added.
You must add your Db2 database as a Db2 data source in DataWorks to access its data. For information about how to add a data source, see Data source management. For information about how to use a Db2 data source in DataWorks, see Db2 data source.
NoteDb2 nodes support only Db2 data sources that are created with a Java Database Connectivity (JDBC) connection string.
-
The network connection between the data source and the resource group has been established.
Ensure the data source can connect to the resource group's network. For information about how to configure the network connection, see Network connection solutions.
(Optional, for RAM users) The RAM user for task development must be a member of the workspace with the Develop or Workspace Administrator role. The Workspace Administrator role has extensive permissions and should be granted with caution. For more information about how to add members and grant roles, see Add workspace members.
Limitations
This feature is supported in the following regions: China (Hangzhou), China (Shanghai), China (Beijing), China (Zhangjiakou), China (Shenzhen), China (Chengdu), China (Hong Kong), Singapore, Malaysia (Kuala Lumpur), Germany (Frankfurt), US (Silicon Valley), and US (Virginia).
Step 1: Create a Db2 node
Go to the DataStudio page.
Log on to the DataWorks console. In the top navigation bar, select the desired region. In the left-side navigation pane, choose . On the page that appears, select the desired workspace from the drop-down list and click Go to Data Development.
-
Right-click the target workflow and choose .
-
In the Create Node dialog box, enter a Name for the node and click OK. After the node is created, you can develop and configure the task in the node editor.
Step 2: Develop the Db2 task
(Optional) Select a Db2 data source
If multiple Db2 data sources exist in your workspace, you must select the desired data source on the node editor page. If only one Db2 data source exists, the data source is used by default.
Db2 nodes support only Db2 data sources that are created with a Java Database Connectivity (JDBC) connection string.
Develop SQL code: simple example
In the Db2 node's code editor, write the SQL code for your task.
SELECT * FROM usertablename;
Develop SQL code: use scheduling parameters
DataWorks provides Scheduling Parameter to let you dynamically pass values to variables in your code for periodically scheduled tasks. You can define variables in your task code in the ${Variable} format. Then, in the right-side navigation pane of the node editor, go to Scheduling Configuration > Scheduling Parameter to assign a value to the variable. For more information about the supported formats and configurations, see Formats of scheduling parameters and Configure and use scheduling parameters.
SELECT '${var}'; -- Can be used with scheduling parameters.
Step 3: Configure task scheduling
To run the task periodically, click Properties in the right-side pane of the node editor to configure its scheduling properties. For more information, see Overview of task scheduling properties.
Before you can submit the node, you must set its Rerun property and specify its parent nodes.
Step 4: Debug the task
Debug the task to ensure it runs as expected.
(Optional) Select a resource group and assign values to custom parameters.
Click the
icon in the toolbar. In the Parameters dialog box, select the resource group that you want to use for debugging.If your code uses scheduling parameters, you can assign values to them here for debugging. For more information about the value assignment logic, see Task debugging process.
Save and run the code.
Click the
icon in the toolbar to save the code. Then, click the
icon to run the task.(Optional) Perform smoke testing.
If you want to perform smoke testing in the development environment to check whether the scheduled task runs as expected, you can do so when you submit the node or after it is submitted. For more information, see Perform smoke testing.
Step 5: Submit and deploy
After you configure the node, submit and deploy it.
Click the
icon in the toolbar to save the node.Click the
icon in the toolbar to submit the node task.In the Submit dialog box, enter a Change description and select whether to perform a code review after submission.
NoteBefore you can submit the node, you must set its Rerun property and specify its parent nodes.
Code review improves code quality and prevents errors from being deployed. If you enable code review, a reviewer must approve the code before it can be deployed. For more information, see Code review.
If you are using a workspace in standard mode, you must deploy the task to the production environment after it is submitted. To do this, click Deploy in the upper-right corner of the node editor. For more information, see Deploy a task.
What's next
After the task is published, it runs on a recurring schedule based on the node's configuration. Click O&M in the upper-right corner of the node configuration tab to go to Operation Center, where you can view the scheduling and running status of the task. For more information, see Manage recurring tasks.