This topic describes how to use SQL statements to write Flink data to ApsaraDB ClickHouse.
You can use SQL statements to write Flink data to ApsaraDB ClickHouse only when the compute engine of Realtime Compute for Apache Flink is Ververica Runtime (VVR) 3.0.2 or later.
- Log on to the console of fully managed Flink and create a job.
- Log on to the Realtime Compute for Apache Flink console.
- On the Fully Managed Flink tab, find the workspace that you want to manage and click Console in the Actions column.
- In the left-side navigation pane, click Draft Editor.
- Click New.
- In the New Draft dialog box, configure the parameters of the job. The following table describes the
Parameter Description Name The name of the job.Note The job name must be unique in the current project. Type You must set the value of this parameter to STREAM / SQL.Streaming jobs and batch jobs support the following file types:
Note Only Realtime Compute for Apache Flink that uses Ververica Runtime (VVR) 3.0.1 or later supports batch jobs.
Deployment Target The cluster in which the job is deployed. You must select a cluster type before you can select a cluster. The following cluster types are supported:
Note If you need to enable the SQL preview feature, you must select Session Clusters and turn on Use for SQL Editor previews. For more information, see Debug a job and Configure a development and test environment (session cluster).
- Per-Job Clusters: suitable for jobs that consume a large number of resources or jobs that run in a continuous and stable manner. This is the default value. Each job requires an independent JobManager to achieve resource isolation between jobs. Therefore, the resource utilization of JobManagers for jobs that involve a small amount of data is low.
- Session Clusters: suitable for jobs that consume few resources or jobs that start and stop frequently. Multiple jobs can reuse the same JobManager. This improves the resource utilization of the JobManager.
Location The folder in which the code file of the job is saved.
You can click the icon to the right of an existing folder to create a subfolder.
- Click OK.
- On the Draft Editor page, write and run the code.
- Create a source table and a result table. Then, insert data from the source table
into the result table.
-- Create a source table named sls_test_single_local. CREATE TEMPORARY TABLE sls_test_single_local ( id INT, name VARCHAR, age BIGINT, rate FLOAT ) WITH ( 'connector' = 'datagen', 'rows-per-second' = '50' ); -- Create a result table named clickhouse_output. CREATE TEMPORARY TABLE clickhouse_output ( id INT, name VARCHAR, age BIGINT, rate FLOAT ) WITH ( 'connector' = 'clickhouse', 'url' = 'jdbc:clickhouse://demo.aliyuncs.com:8123', 'userName' = 'test', 'password' = '280226Ck', 'tableName' = 'sls_test_single_local' ); -- Insert data from the source table into the result table. INSERT INTO clickhouse_output SELECT id, name, age, rate FROM sls_test_single_local;Note For more information about the syntax for creating a result table, see Create a ClickHouse result table.
- Click Save.
- Click Validate.
- Click Publish.
- In the Publish the draft dialog box, click OK to publish the code to the production environment.
- In the Draft is published successfully, please check operations for details message, click operations.
- Create a source table and a result table. Then, insert data from the source table into the result table.
- On the Deployments page, start the job.
- Click Start in the upper-right corner.
- On the Deployment Starting Configuration page, click Start.
- Query tables in ApsaraDB ClickHouse.
- Log on to the ApsaraDB for ClickHouse console.
- In the upper-left corner, select the region where the cluster deployed with the data synchronization job is located.
- On the Clusters page, click the Default Instances tab. Find the cluster deployed with the data synchronization job and click the cluster ID.
- On the Cluster Details page, click Log On to Database in the upper-right corner.
- In the Log on to Database Instance dialog box, enter the username and password of your database account and click Login.
- Enter a query statement and click Execute(F8). In this example, the following sample statement is executed:
select * from db01.sls_test_single_local;The following result is returned.