All Products
Search
Document Center

DataWorks:Synchronize data

Last Updated:Aug 25, 2026

This tutorial describes how to create HttpFile and MySQL data sources to access user information and website log data. You will configure a data synchronization pipeline to transfer this data to the OSS bucket you created during environment setup. Then, you will create an EMR Hive external table to parse the data stored in OSS and run queries to verify the synchronization results.

Prerequisites

  • Before you begin, prepare the required environment. For more information, see Prepare an environment.

  • To ensure network connectivity, in the ECS console, add a security group rule to the security group that is bound to the EMR cluster you created to open port 10000 for inbound traffic and set the authorization object to the CIDR block of the vSwitch in the VPC of the resource group. For more information, see Add a security group rule.

Step 1: Add data sources

Add the following data sources to your DataWorks workspace to access and store the test data.

  • MySQL data source: A test data source provided by DataWorks that stores basic user information.

  • HttpFile data source: A test data source provided by DataWorks that stores user website access logs.

  • OSS data source: The EMR OSS-HDFS storage that you created in Prepare an EMR environment. This data source stores the test data, including basic user information and website access logs, synchronized from the MySQL and HttpFile data sources.

Add a MySQL data source ( user_behavior_analysis_mysql)

The basic user information for this tutorial is stored in a MySQL database. You need to create a MySQL data source to retrieve the basic user information data (ods_user_info_d).

  1. Log on to the DataWorks console. In the target region, click More > Management Center in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Management Center.

  2. On the Management Center page, click Data Source in the left-side navigation pane.

  3. Click Add Connection, search for, and then select the MySQL data source type.

  4. On the Add MySQL Data Source page, configure the parameters. For this tutorial, use the same example values for both the development and production environments.

    The following table describes the key parameters. You can keep the default values for other parameters.

    Parameter

    Description

    Data Source Name

    Enter a data source name. For this tutorial, enter user_behavior_analysis_mysql.

    Description

    A dedicated test data source for DataWorks tutorials. You can read the test data provided by the platform when you configure a batch synchronization task for a single table. This data source supports reads only in Data Integration scenarios and cannot be used in other modules.

    Configuration Mode

    Select User-created Data Store with Public IP Addresses.

    Connection Address

    • Host IP address: rm-bp1z69dodhh85z9qa.mysql.rds.aliyuncs.com

    • Port: 3306

    Database Name

    Enter a database name. For this tutorial, enter workshop.

    Username

    Enter a username. For this tutorial, enter workshop.

    Password

    Enter a password. For this tutorial, enter workshop#2017.

    Authentication Method

    No authentication.

  5. In the Connection Configuration section, click Test Connectivity for both the production and development environment, and make sure that the connectivity status is Connectable.

    Important
    • Make sure that the resource group is associated with the workspace and has public network access configured. Otherwise, errors will occur during subsequent data synchronization. For configuration steps, see Prepare the environment.

    • If no resource group is available, follow the instructions in the connection configuration section, and click Go to Buy and Associate Purchased Resource Group.

  6. Click Complete Creation.

Add an HttpFile data source ( user_behavior_analysis_httpfile)

The user website access log data for this tutorial is stored in an OSS bucket used by the DataWorks platform for testing. You need to create an HttpFile data source to retrieve the user website access logs (user_log.txt).

  1. Go to the data source page.

    1. Log on to the DataWorks console. In the target region, click More > Management Center in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Management Center.

    2. On the Management Center page, click Data Source in the left-side navigation pane.

  2. Click Add Connection, search for, and then select the HttpFile data source type.

  3. On the Add HttpFile Data Source page, configure the parameters. For this tutorial, use the same example values for both the development and production environments.

    The following table describes the key parameters. You can keep the default values for other parameters.

    Parameter

    Description

    Data Source Name

    Enter a data source name. For this tutorial, enter user_behavior_analysis_httpfile.

    Description

    A dedicated test data source for DataWorks tutorials. You can read the test data provided by the platform when you configure a batch synchronization task for a single table. This data source supports reads only in Data Integration scenarios and cannot be used in other modules.

    URL Domain

    Set the URL Domain to https://dataworks-workshop-2024.oss-cn-shanghai.aliyuncs.com for both the development and production environments.

  4. In the Connectivity Configuration section, click Test Connectivity for both the production and development environments and make sure the connectivity status is Connectable.

    Important
    • Make sure the resource group is associated with the workspace and has Internet access configured. Otherwise, errors will occur during subsequent data synchronization. For the configuration steps, see Purchase and configure a resource group.

    • If no resource groups are available, follow the instructions in the connectivity configuration section and click Go to Buy and Associate Purchased Resource Group.

  5. Click Complete Creation.

Add an OSS data source (test_g)

Perform the following steps to add the OSS storage you created in Prepare an EMR environment to DataWorks so that you can store the data synchronized from the MySQL and HttpFile data sources.

Note

When you add an OSS data source, make sure that the current account has the AliyunOSSFullAccess (Object Storage Service) permission. For more information, see Grant permissions to a RAM user and Create an AccessKey pair.

  1. Log on to the DataWorks console. In the target region, click More > Management Center in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Management Center.

  2. On the Management Center page, click Data Source in the left-side navigation pane.

  3. Click Add Connection, search for, and then select the OSS data source type.

  4. On the Add OSS Data Source page, configure the parameters. For this tutorial, use the same example values for both the Development Environment and Production Environment.

    Parameter

    Description

    Data Source Name

    Enter a data source name. In this example, enter test_g.

    Description

    Enter a brief description of the data source.

    Access mode

    Select Access Key mode.

    AccessKey ID

    The AccessKey ID of the current account.

    Log on to the DataWorks console, hover over the user icon in the upper-right corner of the top navigation bar, go to AccessKey Management, and obtain the AccessKey ID of a RAM user that has the required permissions.

    AccessKey Secret

    Enter the AccessKey Secret of the current account.

    Important

    The AccessKey Secret is displayed only when it is created. You cannot view it again. Keep it secure. If the AccessKey pair is leaked or lost, delete it and create a new AccessKey pair.

    Region

    Select the China (Shanghai) region.

    Endpoint

    Enter oss-cn-shanghai-internal.aliyuncs.com.

    Bucket

    The name of the OSS bucket that you configured when you created the EMR cluster during environment setup. In this example, the value is dw-emr-demo.

  5. In the Connection Configuration section, click Test Connectivity for both the production and development environment, and make sure that the connectivity status is Connectable.

    Important
    • Make sure that the resource group is associated with the workspace and has public network access configured. Otherwise, errors will occur during subsequent data synchronization. For configuration steps, see Prepare the environment.

    • If no resource group is available, follow the instructions in the connection configuration section, and click Go to Buy and Associate Purchased Resource Group.

  6. Click Complete Creation.

Step 2: Create synchronization pipelines

In this step, you will create synchronization pipelines to transfer the basic user information and website access log data to Hive tables in preparation for subsequent data processing.

  1. Go to the Workspaces page in the DataWorks console. In the top navigation bar, select a desired region. Find the desired workspace and choose Shortcuts > Data Studio in the Actions column.

  2. In the left-side navigation pane of the Data Studio page, click image to go to the DataStudio page and select Project Directory in the left-side directory tree.

  3. Create a directory named work and a workflow named workshop_emr. For more information, see Create a directory and Create a workflow.

  4. Click the workshop_emr workflow to go to the workflow orchestration page and create a virtual node, batch synchronization nodes, and EMR Hive nodes.

    1. Drag General > Zero-Load Node to the canvas on the right. In the Add Node dialog, enter workshop_start_emr as the Node Name and click Confirm.

    2. Drag two Data Integration nodes to the canvas on the right. In the Add Node dialog, set the source type to MySQL, set the destination type to OSS, set the specific type to Single-table offline, and set the Node Name to ods_user_info_d_2oss_emr and ods_raw_log_d_2oss_emr respectively. These nodes are used to synchronize MySQL user information and HttpFile log data to the OSS bucket you created. Click Confirm.

    3. Drag two EMR > EMR Hive nodes to the canvas on the right. In the Add Node dialog, set the Node Name to ods_user_info_d_emr and ods_raw_log_d_emr respectively. These nodes are used to load data from the OSS bucket you created into Hive tables. Click Confirm.

    The following table describes the node names and purposes in this tutorial:

    Node type

    Node name

    Purpose

    image Virtual node

    workshop_start_emr

    Used to coordinate the entire user profiling workflow, making the data flow path clearer. This node is a Dry-Run Node and does not require code.

    image Batch synchronization node

    ods_user_info_d_2oss_emr

    Used to synchronize the basic user information stored in MySQL to the OSS data source (test_g) you created.

    image Batch synchronization node

    ods_raw_log_d_2oss_emr

    Used to synchronize the user website access logs stored in the HttpFile data source (OSS) to the OSS data source (test_g) you created.

    image EMR Hive node

    ods_user_info_d_emr

    Used to parse the basic user information stored in the OSS data source (test_g) you created into the Hive ods_user_info_d_emr table.

    image EMR Hive node

    ods_raw_log_d_emr

    Used to parse the user website access logs stored in the OSS data source (test_g) you created into the Hive ods_raw_log_d_emr table.

  5. On the workflow orchestration panel, drag to connect the workshop_start_emr node as the upstream node of the two batch synchronization nodes. The final result is as follows:

    image

Step 3: Configure synchronization tasks

Perform the following steps to synchronize the user information from the MySQL data source and the log data from the HttpFile data source to the OSS bucket you created. Then, create Hive external tables to parse the data stored in OSS.

Configure the virtual node

Follow these steps to configure the schedule settings for the virtual node.

  1. Open the virtual node.

    On the workflow orchestration page, hover over the virtual node and click Open Node that appears above it to go to the virtual node editing page.

  2. Configure the virtual node.

    Open the Scheduling Configuration panel on the right side of the node and configure the following parameters.

    Parameter

    Description

    Scheduling Resource Groups

    Select the serverless resource group you created during environment setup.

    Node dependency configuration

    The workflow has no upstream dependency and does not require configuration. For easier management, you can click Using the Workspace Root Node to attach the workflow to the workspace root node.

    The workspace root node is named in the format workspace name_root.

  3. Save the virtual node.

    After you complete the configuration, click the image icon on the toolbar to save the node.

Synchronize user information from the MySQL data source to the OSS data source

Follow these steps to synchronize the user information from the MySQL data source to the OSS bucket you created.

  1. Open the batch synchronization node.

    On the workflow orchestration page, hover over the batch synchronization node ods_user_info_d_2oss_emr and click Open Node that appears above it to go to the task configuration page.

  2. Configure the data source and runtime resource.

    Configure the data source and resource group based on the following parameters.

    Parameter

    Description

    Source

    • Data source: MySQL.

    • Data Source Name: user_behavior_analysis_mysql.

    Destination

    • Data going: OSS.

    • Data Source Name: Select the OSS data source you created earlier. In this example, select test_g.

    Running Resources

    For Resource Group, select the serverless resource group you purchased.

  3. Configure the source and destination.

    1. The following table describes the key parameters. You can keep the default values for other parameters.

      Parameter

      Description

      Data source

      • Table: Select ods_user_info_d from the data source.

      • Shard Key: We recommend that you use a primary key or an indexed column as the split key. Only integer columns are supported. Set the split key to uid.

      Data going

      • File Type: Select text.

      • Object Name (Path Included): Enter the path based on your OSS directory. In this example, enter ods_user_info_d/user_${bizdate}/user_${bizdate}.txt. In this path, ods_user_info_d is the OSS directory name, and $bizdate retrieves the date of the previous day.

      • Field Delimiter: Enter | as the column delimiter.

    2. Verify the Field Mapping and Advanced Configuration.

      DataWorks maps source columns to destination columns so that data from specified source columns is written to specified destination columns. You can also configure the concurrency and dirty data handling policy in the advanced settings. In this tutorial, set Policy for Dirty Data Records to Disallow Dirty Data Records and keep the default values for other settings. For more information, see Configure a batch synchronization task.

  4. Configure debug parameters.

    On the configuration page, click Run Configuration on the right side. Configure the following parameters to test the run in Step 4.

    Configuration item

    Configuration

    Resource Group

    Select the serverless resource group you purchased in Prepare an environment.

    Script Parameters

    No configuration is required. The sample code in this tutorial uses ${bizdate} uniformly to represent the business date. When you debug the workflow in Step 4, set This operation value to a specific constant (for example, 20250223). The task run will use this constant to replace the variables defined in the task.

  5. Save the batch synchronization task.

    After you complete the configuration, click the image icon on the toolbar to save the node.

Synchronize log data from the HttpFile data source to the OSS data source

Follow these steps to synchronize the log data from the HttpFile data source to the OSS bucket you created.

  1. Open the batch synchronization node.

    On the workflow orchestration page, hover over the batch synchronization node ods_raw_log_d_2oss_emr and click Open Node that appears above it to go to the task configuration page.

  2. Configure the data source and runtime resource.

    Configure the data source and resource group based on the following parameters.

    Parameter

    Description

    Data source

    • Data source: HttpFile.

    • Data Source Name: user_behavior_analysis_httpfile.

    Data going

    • Data going: OSS.

    • Data Source Name: Select the OSS data source you created earlier. In this example, select test_g.

    Running Resources

    For Resource Group, select the serverless resource group you purchased.

  3. Configure the source and destination.

    1. The following table describes the key parameters. You can keep the default values for other parameters.

      Parameter

      Description

      Source

      • File Path: /user_log.txt.

      • File Type: Select text.

      • Field Delimiter: Enter | as the column delimiter.

      • Compression Format: Four types are available: None, Gzip, Bzip2, and Zip. Select None.

      • Skip Header: Select No.

      Destination

      • File Type: Select text.

      • Object Name (Path Included): Enter the path based on your OSS directory. In this example, enter ods_raw_log_d/log_${bizdate}/log_${bizdate}.txt. In this path, ods_raw_log_d is the OSS directory name, and $bizdate retrieves the date of the previous day.

      • Field Delimiter: Enter | as the column delimiter.

    2. Configure debug parameters.

      On the configuration page, click Run Configuration on the right side. Configure the following parameters to test the run in Step 4.

      Configuration item

      Configuration

      Resource Group

      Select the serverless resource group you purchased in Prepare an environment.

      Script Parameters

      No configuration is required. The sample code in this tutorial uses ${bizdate} uniformly to represent the business date. When you debug the workflow in Step 4, set This operation value to a specific constant (for example, 20250223). The task run will use this constant to replace the variables defined in the task.

  4. Save the batch synchronization task.

    After you complete the configuration, click the image icon on the toolbar to save the node.

Step 4: Parse OSS data

After the batch synchronization tasks are completed, perform the following steps to create Hive external tables to parse the test data stored in the test_g data source (OSS).

Create the ods_user_info_d_emr table to parse data

  1. Develop code.

    On the workflow orchestration page, hover over the EMR Hive node ods_user_info_d_emr and click Open Node that appears above it to go to the EMR Hive node editing page. Enter the following sample SQL statements.

    CREATE EXTERNAL TABLE IF NOT EXISTS ods_user_info_d_emr
    (
        `uid` STRING COMMENT 'User ID',
        `gender` STRING COMMENT 'Gender',
        `age_range` STRING COMMENT 'Age range',
        `zodiac` STRING COMMENT 'Zodiac sign'
    ) PARTITIONED BY (
      dt STRING
    )
    ROW FORMAT  delimited fields terminated by '|'
    LOCATION 'oss://dw-emr-demo/ods_user_info_d/';
    
    ALTER TABLE ods_user_info_d_emr ADD IF NOT EXISTS PARTITION (dt='${bizdate}')
    LOCATION 'oss://dw-emr-demo/ods_user_info_d/user_${bizdate}/';
    Note

    The LOCATION in the preceding code is a sample path, which is the same as the destination path you configured for the batch synchronization task. Enter the file path you created. In this path, dw-emr-demo is the OSS bucket name you created during environment setup.

  2. Configure debug parameters.

    On the configuration page, click Debug Configuration on the right side. Configure the following parameters to test the run during debugging.

    Configuration item

    Configuration

    Computing Resources

    Select the EMR compute resource associated during environment setup.

    Resource Group

    Select the serverless resource group you purchased in Prepare an environment.

    Script Parameters

    No configuration is required. The sample code in this tutorial uses ${bizdate} uniformly to represent the business date. When you debug a task, set This operation value to a specific constant (for example, 20250223). The task run will use this constant to replace the variables defined in the task.

  3. After you complete the configuration, click Save to save the node.

Create the ods_raw_log_d_emr table to parse data

  1. Develop code.

    On the workflow orchestration page, hover over the EMR Hive node ods_raw_log_d_emr and click Open Node that appears above it to go to the EMR Hive node editing page. Enter the following sample SQL statements.

    --Create target table for OSS logs
    CREATE EXTERNAL TABLE IF NOT EXISTS ods_raw_log_d_emr
    (
      `col` STRING
    ) PARTITIONED BY (
      dt STRING
    );
    ALTER TABLE ods_raw_log_d_emr ADD IF NOT EXISTS PARTITION (dt='${bizdate}')
    LOCATION 'oss://dw-emr-demo/ods_raw_log_d/log_${bizdate}/';
    Note

    The LOCATION in the preceding code is a sample path, which is the same as the destination path you configured for the batch synchronization task. Enter the file path you created. In this path, dw-emr-demo is the OSS bucket name you created during environment setup.

  2. Configure debug parameters.

    On the configuration page, click Debug Configuration on the right side. Configure the following parameters to test the run during debugging.

    Configuration item

    Configuration

    Computing Resources

    Select the EMR compute resource associated during environment setup.

    Resource Group

    Select the serverless resource group you purchased in Prepare an environment.

    Script Parameters

    No configuration is required. The sample code in this tutorial uses ${bizdate} uniformly to represent the business date. When you debug a task, set This operation value to a specific constant (for example, 20250223). The task run will use this constant to replace the variables defined in the task.

  3. Save and run the node.

    After you complete the configuration, click Save and then Run to run the node.

Step 5: Run synchronization tasks

  1. Configure the workflow schedule.

    On the right side of the workflow orchestration page, click Scheduling Configuration and configure the parameters. The following table describes the key parameters. You can keep the default values for other parameters.

    Schedule settings parameter

    Description

    Scheduling Parameters

    Configure scheduling parameters for the entire workflow. Internal nodes of the workflow can directly use these parameters. In this tutorial, set this parameter to bizdate=$[yyyymmdd-1] to retrieve the date of the previous day.

    Scheduling period

    In this tutorial, set this parameter to Day.

    Scheduling time

    In this tutorial, set Scheduling time to 00:30. The workflow will start running at 00:30 every day.

    Node dependency configuration

    The workflow has no upstream dependency and does not require configuration. For easier management, you can click Using the Workspace Root Node to attach the workflow to the workspace root node.

    The workspace root node is named in the format workspace name_root.

  2. After you configure the workflow schedule, click Run on the toolbar at the top of the workflow canvas. Set the values for the parameter variables defined in each node for this run (this tutorial uses 20250223, but you can modify the value as needed) and click OK. Wait for the run to complete.

    • If the ods_raw_log_d_emr and ods_user_info_d_emr nodes are in the image.png state, the synchronization was executed successfully.

    • If the ods_raw_log_d_emr and ods_user_info_d_emr nodes are in the image state and the error java.net.ConnectException: Connection timed out (Connection timed out) occurs, add a security group rule in the ECS console to open port 10000 for the ECS instance and set the authorization object to the CIDR block of the vSwitch in the VPC of the resource group. You can click Network Settings for the corresponding resource group in the resource group list to obtain the vSwitch CIDR block. For more information about how to add a security group rule, see Add a security group rule.

Note

The data synchronization may take a long time, approximately 24 minutes.

Step 6: Verify the data synchronization results

  1. Go to the Workspaces page in the DataWorks console. In the top navigation bar, select a desired region. Find the desired workspace and choose Shortcuts > Data Studio in the Actions column.

  2. On the Data Studio page, click image in the primary navigation pane to go to data development, and find the Project Directory section in the secondary navigation pane.

  3. Right-click the work directory you created and choose New Node... > EMR > EMR Hive. Enter a custom EMR Hive node name and press Enter to create the node.

    On the EMR Hive node editing page, replace the business date in the following script with the current business date to verify the data synchronization results. Query the number of records imported to the ods_raw_log_d_emr and ods_user_info_d_emr tables respectively.

    Note

    The partition column in the query statement must be updated to the business date. For example, if the task run date is 20250223, the business date is 20250222, which is the day before the task run date.

    SELECT * FROM ods_user_info_d_emr WHERE dt=business_date; 
    SELECT * FROM ods_raw_log_d_emr WHERE dt=business_date; 
    • If the preceding queries return data, the data processing is complete.

    • If no data is returned, make sure that the This operation value configured when running the workflow matches the business date specified in dt in the query. You can click the workflow, click Runtime Logs on the right side, click View in the Operation column of the run history, and then check the business date value (partition=[pt=xxx]) in the workflow runtime log.

Next step

You have learned how to synchronize log data and complete data synchronization. You can continue to the next tutorial, in which you will learn how to process and analyze the synchronized data. For more information, see Process data.