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
10000for 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).
Log on to the DataWorks console. In the target region, click in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Management Center.
On the Management Center page, click Data Source in the left-side navigation pane.
Click Add Connection, search for, and then select the MySQL data source type.
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.comPort:
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.
In the Connection Configuration section, click Test Connectivity for both the production and development environment, and make sure that the connectivity status is Connectable.
ImportantMake 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.
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).
Go to the data source page.
Log on to the DataWorks console. In the target region, click in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Management Center.
On the Management Center page, click Data Source in the left-side navigation pane.
Click Add Connection, search for, and then select the HttpFile data source type.
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.comfor both the development and production environments.In the Connectivity Configuration section, click Test Connectivity for both the production and development environments and make sure the connectivity status is Connectable.
ImportantMake 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.
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.
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.
Log on to the DataWorks console. In the target region, click in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Management Center.
On the Management Center page, click Data Source in the left-side navigation pane.
Click Add Connection, search for, and then select the OSS data source type.
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 IDof a RAM user that has the required permissions.AccessKey Secret
Enter the AccessKey Secret of the current account.
ImportantThe 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.In the Connection Configuration section, click Test Connectivity for both the production and development environment, and make sure that the connectivity status is Connectable.
ImportantMake 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.
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.
Go to the Workspaces page in the DataWorks console. In the top navigation bar, select a desired region. Find the desired workspace and choose in the Actions column.
In the left-side navigation pane of the Data Studio page, click
to go to the DataStudio page and select Project Directory in the left-side directory tree.Create a directory named
workand a workflow namedworkshop_emr. For more information, see Create a directory and Create a workflow.Click the
workshop_emrworkflow to go to the workflow orchestration page and create a virtual node, batch synchronization nodes, and EMR Hive nodes.Drag to the canvas on the right. In the Add Node dialog, enter
workshop_start_emras the Node Name and click Confirm.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_emrandods_raw_log_d_2oss_emrrespectively. These nodes are used to synchronize MySQL user information and HttpFile log data to the OSS bucket you created. Click Confirm.Drag two nodes to the canvas on the right. In the Add Node dialog, set the Node Name to
ods_user_info_d_emrandods_raw_log_d_emrrespectively. 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
Virtual nodeworkshop_start_emrUsed 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.
Batch synchronization nodeods_user_info_d_2oss_emrUsed to synchronize the basic user information stored in MySQL to the OSS data source (
test_g) you created.
Batch synchronization nodeods_raw_log_d_2oss_emrUsed to synchronize the user website access logs stored in the HttpFile data source (OSS) to the OSS data source (
test_g) you created.
EMR Hive nodeods_user_info_d_emrUsed to parse the basic user information stored in the OSS data source (
test_g) you created into the Hiveods_user_info_d_emrtable.
EMR Hive nodeods_raw_log_d_emrUsed to parse the user website access logs stored in the OSS data source (
test_g) you created into the Hiveods_raw_log_d_emrtable.On the workflow orchestration panel, drag to connect the
workshop_start_emrnode as the upstream node of the two batch synchronization nodes. The final result is as follows:
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.
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.
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.Save the virtual node.
After you complete the configuration, click the
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).
Step 5: Run synchronization tasks
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 at00:30every 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.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
state, the synchronization was executed successfully.If the ods_raw_log_d_emr and ods_user_info_d_emr nodes are in the
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 port10000for 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.
The data synchronization may take a long time, approximately 24 minutes.
Step 6: Verify the data synchronization results
Go to the Workspaces page in the DataWorks console. In the top navigation bar, select a desired region. Find the desired workspace and choose in the Actions column.
On the Data Studio page, click
in the primary navigation pane to go to data development, and find the Project Directory section in the secondary navigation pane.Right-click the
workdirectory 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.
NoteThe 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 is20250222, 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
dtin 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.