This topic describes how to use an EMR Hive node in DataWorks to process data from the user information table (ods_user_info_d_emr) and the access log data table (ods_raw_log_d_emr) that were synchronized to OSS, and generate the target user profile data.
Prerequisite
Before you begin, complete the steps in Synchronize data.
Step 1: Build the data processing workflow
Double-click the workshop_emr workflow that you created in Synchronize data to open the workflow orchestration page and add more workflow nodes.
Create and name three EMR Hive nodes: dwd_log_info_di_emr, dws_user_info_all_di_emr, and ads_user_info_1d_emr. Then, configure their dependencies as shown in the following figure.
This table describes the nodes and their functions.
|
Node type |
Node name |
Function |
|
|
dwd_log_info_di_emr |
Cleanses raw OSS log data by using built-in and custom functions (such as |
|
|
dws_user_info_all_di_emr |
Aggregates the basic user information table ( |
|
|
ads_user_info_1d_emr |
Further processes data from the |
Step 2: Register a custom function
To ensure smooth data processing in subsequent steps, you must register an EMR custom function (getregion) to parse the log data structure synchronized to EMR during the data synchronization phase into a table.
Upload an EMR JAR resource (ip2region.jar)
-
Download the resource JAR package.
Download ip2region-emr.jar.
-
Create an EMR JAR resource.
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, click
to go to the resource management page. -
On the Resource Management page, click New, select the EMR Jar resource type, and specify a custom resource name.
-
Go to the resource editing page and configure the EMR JAR resource. The following table describes the key parameters.
Parameter
Description
Document Source
Select Local.
Document Content
Click Upload the downloaded resource JAR package
ip2region-emr.jar.Storage Path
Select OSS.
Select the OSS bucket that you configured when creating the EMR cluster in the environment preparation phase.
Data Source
Select the compute resource that you associated in the data synchronization phase.
Resource Group
Select the serverless resource group that you created in the environment preparation phase.
-
Click Save, and then click Publish to deploy the resource to the development and production environments.
Register an EMR function (getregion)
-
Create a function.
Right-click the EMR JAR resource you created, choose , set the function name to
getregion, and click Confirm to create the function. -
Register the function.
Go to the function configuration page and configure the EMR Function. The following table describes the key parameters.
Parameter
Description
Function type
Select OTHER.
Data Source
Select the compute resource that you associated in the data synchronization phase.
The EMR database
Select Default.
Resource Group
Select the serverless resource group that you created in the environment preparation phase.
Responsible Person
You can select an owner who has the required permissions.
Class Name
org.alidata.emr.udf.Ip2Region.Resource List
Select the name of the EMR JAR resource that you created.
-
Deploy the function.
Click Save, and then click Publish to deploy the function to the development and production environments.
Step 3: Configure EMR nodes
Data processing requires the processing logic of each layer to be implemented through EMR Hive scheduling. This tutorial provides complete sample SQL code for data processing. You need to configure the following nodes in sequence: dwd_log_info_di_emr, dws_user_info_all_di_emr, and ads_user_info_1d_emr.
Step 4: Process data
-
Process data.
In the toolbar at the top of the workflow canvas, click Run. Set the values of the parameter variables defined for each node for this run (this tutorial uses
20250223; you can modify the value as needed). Click OK and wait for the run to complete. -
Verify the data processing 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.
-
In the left-side navigation pane of the Data Studio page, click
to go to the DataStudio page. In the left-side directory tree, select Project Directory. -
Right-click the
workdirectory that you created, choose , specify a custom EMR Hive node name, and click Confirm to create the node. -
Go to the EMR Hive node editing page, replace the business date in the following script with the actual business date, and verify the data synchronization results. Check the number of records imported into ods_raw_log_d_emr and ods_user_info_d_emr.
NoteThe partition column
dtin the query statement must be updated to the actual business date. For example, if the task runs on20250223, the business date is20250222, which is the day before the run date.SELECT * FROM ads_user_info_1d_emr WHERE dt=business_date;-
If the preceding commands return data, the data processing is complete.
-
If a query returns a count of zero, ensure the This operation value matches the business date in your query's
dtpartition. To check the value, open the Runtime Logs pane on the right side of the workflow and click View in the Operation column for the run. The run log shows the business date value, for example,partition=[dt=20250223].
-
Step 5: Deploy the workflow
Tasks must be deployed to the production environment before they can be automatically scheduled. You can follow the steps below to deploy the workflow to the production environment.
This tutorial has already configured the scheduling parameters in the workflow schedule settings. You do not need to configure scheduling parameters for each node separately before deployment.
-
In the left-side navigation pane of Data Studio, click
. In the Project Directory section, find the workflow you created and click it to open the workflow dashboard. -
In the toolbar at the top of the page, click Publish to open the deployment panel.
-
Click Start Release Production and follow the deployment process to complete the deployment.
Step 6: Run tasks in the production environment
After deployment, instances are generated and run the next day. You can use Supplementary data to backfill data for the deployed workflow and verify that tasks can run in the production environment. For more information, see Backfill data.
-
After the tasks are deployed, click Operation and Maintenance Center in the upper-right corner.
Alternatively, click the
icon in the upper-left corner and choose . -
In the left-side navigation pane, choose to go to the Auto Triggered Node page, and click the
workshop_start_emrvirtual node. -
In the DAG on the right side, right-click the
workshop_start_emrnode and choose . -
Select the tasks for which you want to backfill data, set the business date, and click Submit and Redirect.
-
On the backfill data page, click Refresh until all tasks run successfully.
After the tutorial is complete, to avoid incurring ongoing costs, you can set a scheduling validity period for the nodes or freeze the root node of the workflow (virtual node workshop_start_emr).
Next steps
-
Analyze data: After the user profile analysis is complete, use the Data Analysis module to visualize the processed data in charts, enabling you to quickly extract key information and gain insights into business trends behind the data.
-
Monitor data quality: Configure data quality monitoring for the tables generated during data processing to identify and block dirty data in advance, preventing the impact of dirty data from spreading.
-
Manage metadata: After the user profile analysis workflow is complete, corresponding data tables are created in the EMR Hive nodes. You can view the generated tables in the Data Map module and use lineage to view the relationships between the tables.
-
Share data through APIs: After you obtain the final processed data, use the Data Service module to share and apply data through standardized data service APIs, providing data to other business modules that receive data through APIs.
icon in the toolbar to save the task node.