Synchronize data with DataWorks

更新时间:
复制 MD 格式

This topic describes how to use DataWorks to synchronize data from MaxCompute to ApsaraDB for ClickHouse.

Background information

You can use DataWorks to synchronize data from various supported data sources to ApsaraDB for ClickHouse in offline mode. For more information about the data source types supported for offline synchronization, see Supported data sources and read/write plug-ins.

Prerequisites

Usage notes

  • ApsaraDB for ClickHouse supports only exclusive resource groups for data integration.

  • If you need to synchronize a table again, run the TRUNCATE TABLE <table_name>; statement to clear the ApsaraDB for ClickHouse table.

Procedure

  1. Create data sources.

    You must create a data source for both MaxCompute and ApsaraDB for ClickHouse.

    Note

    For information about how to create a data source, see Add a MaxCompute compute engine and Add an ApsaraDB for ClickHouse data source.

  2. Create a MaxCompute table.

    1. Log on to the DataWorks console.

    2. In the left-side navigation pane, click Workspace.

    3. In the upper-left corner of the page, select the region of your workspace.

    4. On the Workspace list page, find the target workspace, and in the Actions column, click Quick Access > Scheduled Workflow.

    5. On the Scheduled Workflow page, move the pointer over the 新建 icon and choose Create Table > MaxCompute > Table.

    6. In the Create Table dialog box, select a Path, enter a Name, such as odptabletest1, and then click Create.

    7. In the General section, configure the parameters.

      基本属性

      The following table describes the parameters.

      Parameter

      Description

      Display Name

      The display name of the table.

      theme

      In DataWorks, themes function as folders that define the level-1 and level-2 folders to which the table belongs. Use themes to classify tables by business purpose and group related tables in the same folder.

      Note

      Level-1 and level-2 themes are a visual aid for organizing tables into folders in DataWorks, which helps you manage tables more effectively. You can quickly find a table by its theme on the Table Management page. If no suitable themes are available, you can create one. For more information, see Define table themes.

    8. In the toolbar, click DDL.

    9. In the DDL Statement dialog box, enter the following table creation statement and click Generate Table Schema.

      CREATE TABLE IF NOT EXISTS odptabletest1
      (    
      v1  TINYINT,    
      v2  SMALLINT                
      );
    10. Click Commit to Development Environment and then click Commit to Production Environment.

  3. Write data to the MaxCompute table.

    1. On the Scheduled Workflow page, click Ad Hoc Query in the left-side navigation pane.

    2. Move the pointer over the 新建 icon and choose Create > ODPS SQL.

    3. In the Create Node dialog box, select a Path and enter a Name.

    4. Click OK.

    5. On the node's editor page, enter the following statement.

      insert into odptabletest1 values (1,"a"),(2,"b"),(3,"c"),(4,"d");
    6. In the toolbar, click the 执行 icon.

    7. In the MaxCompute calculation cost estimate window, click Run.

  4. Create an ApsaraDB for ClickHouse table.

    1. Log on to the ApsaraDB for ClickHouse console.

    2. In the upper-left corner of the page, select the region of the destination cluster.

    3. On the Clusters page, select the appropriate instance type for your destination cluster, and then click the cluster ID.

    4. On the Cluster Information page, click Log On to Database in the upper-right corner.

    5. On the Log on to instance page, enter the database account and password, and click Log On.

    6. Enter the table creation statement and click Execute (F8):

      create table default.dataworktest ON CLUSTER default (
      v1 Int, 
      v2 String
      ) ENGINE = MergeTree ORDER BY v1;
      Note

      The schema of the ApsaraDB for ClickHouse table must be compatible with that of the MaxCompute table.

  5. Create a business flow.

    If you already have a Workflow, you can skip this step.

    1. On the Data Analytics page, click Data Analytics in the left-side navigation pane.

    2. Move the pointer over the 新建 icon and select Create Workflow.

    3. In the Create Workflow dialog box, enter a Workflow Name.

      Important

      The business name must be 1 to 128 characters in length and can contain letters, Chinese characters, digits, underscores (_), and periods (.).

    4. Click Create.

  6. Create an offline synchronization node.

    1. Expand the business flow and right-click Data Integration.

    2. Choose Create Node > Batch Synchronization.

    3. In the Create Node dialog box, enter a Name and select a Path.

      Important

      The node name must be 1 to 128 characters in length and can contain letters, Chinese characters, digits, underscores (_), and periods (.).

    4. Click OK.

  7. Configure the data source and destination.

    1. Configure data source: Select the MaxCompute data source.

      选择数据源

      The following table describes the parameters.

      Parameter

      Description

      Data Source

      The type and name of the data source.

      Production Project Name

      You cannot change the default value.

      Table

      The table from which you want to synchronize data.

      Partitions

      If you restrict your daily incremental data to a partition for a specific date, you can use partitions to perform daily incremental updates. For example, set the value of partition v17 to ${bizdate}.

      Note

      DataWorks does not support field mapping for partitioned MaxCompute tables. You must configure partition fields separately.

      Note

      For more information about the parameters, see MaxCompute Reader.

    2. Configure data destination: Select ClickHouse as the data source type.

      选择数据源

      The following table describes the parameters.

      Parameter

      Description

      Data Source

      The type and name of the data source. The data source type must be ClickHouse.

      Table

      The table to which you want to synchronize data.

      Primary or Unique Key Conflict Handling

      This value is fixed to insert into (insert).

      Statement Run Before Writing

      The SQL statements that are executed before the data synchronization task starts.

      Statement Run After Writing

      The SQL statements that are executed after the data synchronization task completes.

      Batch Insert Size (Bytes)

      The maximum data size that can be written per batch.

      Records per Batch

      The number of records that can be written per batch.

    3. (Optional) Field Mapping: You can specify the one-to-one mapping between the Field on the left and the Field on the right.

      字段映射

      Note

      For more information about the parameters, see Configure field mappings.

    4. (Optional) Channel: Configure the job rate limit and dirty data check rules.

      通道控制

      Note

      For more information about the parameters, see Configure channel control policies for batch synchronization tasks.

  8. Configure the resource group for data integration.

    In the right-side pane, click Resource Group configuration and select the Exclusive Data Integration Resource Group that you created.集成资源组配置

  9. Save and run the data synchronization task.

    1. In the toolbar, click the 保存 icon to save the data synchronization task.

    2. In the toolbar, click the 运行 icon to run the data synchronization task.p353650.png

Verify the synchronization result

  1. Log on to the ApsaraDB for ClickHouse console.

  2. In the upper-left corner of the page, select the region of the destination cluster.

  3. On the Clusters page, select the appropriate instance type for your destination cluster, and then click the cluster ID.

  4. On the Cluster Information page, click Log On to Database in the upper-right corner.

  5. On the Log on to instance page, enter the database account and password, and click Log On.

  6. Enter the following query statement and click Execute (F8) to check the result:

    SELECT * FROM dataworktest;

    The query result is as follows:查询结果

    Note

    When you execute a query and it successfully returns a result, this confirms that the data has been synchronized from DataWorks to ApsaraDB for ClickHouse.