ClickHouse SQL allows you to use a distributed SQL query engine to process structured data. This improves running efficiency of jobs. DataWorks provides ClickHouse SQL nodes that you can use to develop and periodically schedule ClickHouse SQL tasks and integrate ClickHouse SQL tasks with other types of tasks. This topic describes how to use a ClickHouse SQL node to develop tasks.
Prerequisites
A workflow is created.
Development operations in different types of compute engines are performed based on workflows in DataStudio. Therefore, before you create a node, you must create a workflow. For more information, see Create a workflow.
An E-MapReduce (EMR) ClickHouse database or cluster is created, and related preparations are made.
EMR engine types include the new Data Lake and Hadoop. The preparations required before you create a node vary depending on the engine type. You can complete the preparations in EMR and DataWorks based on your specific requirements.
DataLake clusters: For information about the preparations, see Configure an EMR DataLake cluster and Configure DataWorks.
A ClickHouse compute resource is associated with the workspace.
You must add your ClickHouse database as a ClickHouse compute resource to DataWorks and associate it with DataStudio before you can access ClickHouse data through the ClickHouse compute resource and perform subsequent development operations.
A serverless resource group is purchased and is associated with the virtual private cloud (VPC) where the ClickHouse cluster is deployed. For more information, see Create and use a serverless resource group.
NoteTasks on ClickHouse SQL nodes can be run on serverless resource groups or old-version exclusive resource groups for scheduling. We recommend that you run tasks on serverless resource groups.
Step 1: Create a ClickHouse SQL 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.
Find the desired workflow, right-click the workflow name, and then choose
.In the Create Node dialog box, configure the Name parameter and click Confirm. Then, you can use the node to develop tasks and configure task scheduling properties.
Step 2: Develop a ClickHouse SQL task
(Optional) Select a ClickHouse instance engine
If you have added multiple ClickHouse compute resources to the desired workspace, you must select a compute resource on the configuration tab of the ClickHouse SQL node before you can use the node to develop tasks. If you have added only one ClickHouse compute resource to the desired workspace, the compute resource is used to develop tasks by default.
Develop SQL code
In the code editor on the configuration tab of the ClickHouse SQL node, write task code. Sample task code:
CREATE DATABASE if not EXISTS ck_test;
CREATE TABLE if not EXISTS ck_test.first_table (
`product_code` String,
`package_name` String
) ENGINE = MergeTree ORDER BY package_name SETTINGS index_granularity = 8192;
INSERT INTO ck_test.first_table (product_code, package_name) VALUES ('1', '1');
SELECT * FROM ck_test.first_table;
Step 3: Configure task scheduling properties
If you want the system to periodically run a task on the node, you can click Properties in the right-side navigation pane on the configuration tab of the node to configure task scheduling properties based on your business requirements. For more information, see Overview.
You must configure the Rerun and Parent Nodes parameters on the Properties tab before you commit the task.
Step 4: Debug task code
You can perform the following operations to check whether the task is configured as expected based on your business requirements:
Optional. Select a resource group and assign custom parameters to variables.
Click the
icon in the top toolbar of the configuration tab of the node. In the Parameters dialog box, select a resource group for scheduling that you want to use to debug and run task code.
If you use scheduling parameters in your task code, assign the scheduling parameters to variables as values in the task code for debugging. For more information about the value assignment logic of scheduling parameters, see Debugging procedure.
Save and execute the SQL statements.
In the top toolbar, click the
icon to save SQL statements. Then, click the
icon to execute the SQL statements.
Optional. Perform smoke testing.
You can perform smoke testing on the task in the development environment to check whether the task is run as expected when you commit the task or after you commit the task. For more information, see Perform smoke testing.
Step 5: Commit and deploy the task
After a task on a node is configured, you must commit and deploy the task. After you commit and deploy the task, the system runs the task on a regular basis based on scheduling configurations.
Click the
icon in the top toolbar to save the task.
Click the
icon in the top toolbar to commit the task.
In the Submit dialog box, configure the Change description parameter. Then, determine whether to review task code after you commit the task based on your business requirements.
NoteYou must configure the Rerun and Parent Nodes parameters on the Properties tab before you commit the task.
You can use the code review feature to ensure the code quality of tasks and prevent task execution errors caused by invalid task code. If you enable the code review feature, the task code that is committed can be deployed only after the task code passes the code review. For more information, see Code review.
If you use a workspace in standard mode, you must deploy the task in the production environment after you commit the task. To deploy a task on a node, click Deploy in the upper-right corner of the configuration tab of the node. For more information, see Deploy tasks.
What to do next
After you commit and deploy the task, the task is periodically run based on the scheduling configurations. You can click Operation Center in the upper-right corner of the configuration tab of the corresponding node to go to Operation Center and view the scheduling status of the task. For more information, see View and manage auto triggered tasks.