Incremental data synchronization

Updated at:

You can create a recurring offline task for incremental data synchronization. This method automatically creates a destination table. This topic describes how to create a recurring offline task to synchronize incremental data from a MySQL database to MaxCompute.

Prerequisites

  1. You have created a workspace named "Information Center (xxzx)". For more information, see Create a workspace.

  2. You have added MaxCompute and RDS MySQL data sources to the workspace. For more information, see Create a compute resource.

  3. You have retrieved the physical tables from the data source. For more information, see Retrieve a physical table.

  4. The RDS MySQL data source contains the `ys_yhkh` table, which is used as the source table for data synchronization. For the table schema and data retrieval script, see RDS script.

Procedure

  1. Log on to the Data Resource Platform console.

  2. In the upper-left corner of the page, choose 菜单 > Collaboration.

  3. In the top menu bar, click the 选择工作组 icon and select the target workspace.

  4. In the navigation pane on the left, click 数据同步.png > Offline Data Synchronization.

  5. On the Offline Data Synchronization page, click Add Task.

  6. On the Offline Data Synchronization management page, configure the recurring offline sync task.

    1. Enter the basic information. Set Task Name to "Credit Card Customer Data to Cloud_Incremental".

    2. In the Source Configuration section, configure the data source.

      Parameter

      Description

      Example

      Data Source

      Required. The type of the source data source and the specific data source that you have added.

      MySQL/dataq_dws_rds

      Data Table

      Required. The source table or file in the data source.

      ys_yhkh (Not in cloud)

      Synchronization Mode

      Required. The mode for data synchronization. You can choose to synchronize full data or incremental data based on an incremental field.

      Because this topic describes an incremental offline sync task, select Incremental.

      Incremental

      Incremental Field

      The field used for incremental synchronization. This can be a numeric, date/time, or string field, or an auto-increment primary key. The system queries and records the latest point (select max(column)) based on the selected field and builds a data filtering statement to perform incremental synchronization. If the current data source does not have a suitable incremental field, use full synchronization or real-time synchronization.

      zjzdjyrq

      Note

      The zjzdjyrq (last active transaction date) field is of the Date type.

      Field Data Type

      This parameter is required if the incremental field is a string.

      Based on the string type, strings are classified as time strings, integer strings, float strings, and general strings. Select the type based on the actual data in the field.

      None

      Data Retrieval Rule

      Optional. The rule for data retrieval. This applies only to date data. yyyy represents a 4-digit year, yy represents a 2-digit year, mm (MM) represents the month, dd represents the day, hh24 represents the hour (use hh for 12-hour format), mi represents the minute, and ss represents the second. You can combine these parameters, such as $[yyyymmdd], $[yyyy-mm-dd], $[hh24miss], $[hh24:mi:ss], and $[yyyymmddhh24miss].

      • The ${} expression retrieves the data timestamp. The minimum unit is day. For example, ${yyyyMMdd} retrieves data from the previous day, and ${yyyyMM-1} retrieves data from the previous month.

      • The $[] expression retrieves the scheduled time. The minimum unit is day. For example, $[yyyyMMdd-1/24] retrieves data from the hour before the current time.

      • The timestamp functions sysMillis (millisecond) and sysSeconds (second) are supported. The unit is day. For example, ${sysMillis} retrieves data from the previous day.

      $[yyyyMMdd-1]

      Note

      Retrieves data from the day before the scheduled time. For example, if the scheduled time is 2022-12-24, the task synchronizes data where the zjzdjyrq field is 2022-12-23.

      Configure Custom Conditions

      Optional. Enter a custom SQL query condition to filter the data to be synchronized.

      gz>10000

      Note

      Synchronizes data of bank customers whose salary (gz) is greater than 10000.

    3. In the Destination Configuration section, configure the destination.

      Parameter

      Description

      Example

      Destination

      The type of the destination data source and the specific data source that you have added.

      MaxCompute/dataq_odps_dev

      Data Table

      The destination table where the data is written.

      If the destination table already exists in the data source, select it from the Data Table drop-down list. If the destination table does not exist, create it as follows:

      1. From the Data Table drop-down list, select Create Destination Object.

      2. In the Create Table dialog box, the system automatically generates the table name, remarks, and fields based on the source data object configured in the previous step. Change the table name to "stg_base_yhkh_demo_di" and set Partition Information to "Non-partitioned table".

      3. After the configuration is complete, click OK to return to the task configuration page.

      stg_base_yhkh_demo_di

      Initial Full Synchronization

      Optional.

      If you check this option, the task performs a full data synchronization the first time it runs.

      Not checked

    4. In the Field Mapping section, Same-name Mapping is selected by default.

    5. In the Parsing Configuration section, you can write a parsing script. This step is optional and is not configured in this topic.

      Note

      After you configure a parsing script, the incremental field configured at the source is no longer parsed. The system directly uses the script to query data from the source.

    6. On the right side of the page, click Scheduling Configuration to configure the task schedule. Two scheduling types are available: Recurring schedule and One-time schedule. This example uses a recurring schedule. For more information, see the following table.

      Parameter

      Description

      Example

      Recurring schedule

      Turn on the recurring schedule switch.

      Recurring schedule

      Effective Date

      Required. Specifies the scope of the custom task.

      2022-12-14 to 9999-01-01

      Scheduling Cycle

      The scheduling cycle for both full and incremental synchronization can be set to minute, hour, day, week, or month.

      • Minute: Set the interval at which the task runs, in minutes.

      • Hour: Set an interval or a specific time.

        • Interval: The interval at which the task runs, in hours.

        • Specific time: The time of day when the task runs. You can select multiple times.

      • Day: Set the specific time of day for the task to run.

      • Week: Select the days of the week and the specific time of day for the task to run. You can select multiple days.

      • Month: Select the days of the month and the specific time of day for the task to run. You can select multiple days.

      Day, 13:15

      Note

      This means the incremental sync task is scheduled to run at 13:15 every day.

  7. After the configuration is complete, in the upper-left corner of the Offline Data Synchronization management page, click the image.png icon.

  8. On the Offline Data Synchronization management page, find the new full offline data synchronization job and click Publish in the Actions column.

Expected results

  1. On the Offline Data Synchronization management page, select the "Credit_Card_Customer_DataQ-DatatoCloud_Incremental" sync task that is in the published state, and click Monitoring in the Actions column. You are redirected to the Service Monitoring page. In the navigation pane on the left, click Offline Computing Instances to view the auto triggered tasks that ran today. You can see that the incremental offline auto triggered sync task ran at the scheduled time "2022-12-14 13:15:00" and completed successfully at "2022-12-14 13:16:31".

  2. Navigate to the Data Query module and click Physical Table Query. Select the destination data source and table: "dataq_odps_dev/stg_base_yhkh_demo_di". In the Data Preview tab, you can see that data where the last active transaction date (zjzdjyrq) is 2022-12-13 and the salary (gz) is greater than CNY 10,000 has been written to the stg_base_yhkh_demo_di table.