All Products
Search
Document Center

DataWorks:Process data

Last Updated:Apr 23, 2026

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

imageEMR Hive node

dwd_log_info_di_emr

Cleanses raw OSS log data by using built-in and custom functions (such as getregion) to split data from the raw log table ods_raw_log_d_emr and write it to dwd_log_info_di_emr's multiple columns.

imageEMR Hive node

dws_user_info_all_di_emr

Aggregates the basic user information table (ods_user_info_d_emr) and the initially processed log data table (dwd_log_info_di_emr), and writes the data to the dws_user_info_all_di_emr table.

imageEMR Hive node

ads_user_info_1d_emr

Further processes data from the dws_user_info_all_di_emr table and writes the data to the ads_user_info_1d_emr table to generate the final user profile data.

image

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)

  1. Download the resource JAR package.

    Download ip2region-emr.jar.

  2. Create an EMR JAR resource.

    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, click image to go to the resource management page.

    3. On the Resource Management page, click New, select the EMR Jar resource type, and specify a custom resource name.

    4. 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.

    5. Click Save, and then click Publish to deploy the resource to the development and production environments.

Register an EMR function (getregion)

  1. Create a function.

    Right-click the EMR JAR resource you created, choose Create Function... > EMR Function, set the function name to getregion, and click Confirm to create the function.

  2. 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.

  3. 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.

Configure the dwd_log_info_di_emr node

  1. Edit the node content.

    On the workflow orchestration page, hover over the EMR Hive node dwd_log_info_di_emr and click Open Node that appears above the node. In the dialog that appears, select Save and Open to go to the EMR Hive node editing page. Enter the following sample SQL statements.

    --Create ODS layer table
    CREATE TABLE IF NOT EXISTS dwd_log_info_di_emr (
      ip STRING COMMENT 'IP address',
      uid STRING COMMENT 'User ID',
      `time` STRING COMMENT 'Time yyyymmddhh:mi:ss',
      status STRING COMMENT 'Server response status code',
      bytes STRING COMMENT 'Bytes returned to client',
      region STRING COMMENT 'Region, derived from IP',
      method STRING COMMENT 'HTTP request type',
      url STRING COMMENT 'URL',
      protocol STRING COMMENT 'HTTP protocol version',
      referer STRING COMMENT 'Referrer URL',
      device STRING COMMENT 'Device type ',
      identity STRING COMMENT 'Access type: crawler feed user unknown'
    )
    PARTITIONED BY (
      dt STRING
    );
    
    ALTER TABLE dwd_log_info_di_emr ADD IF NOT EXISTS PARTITION (dt='${bizdate}');
    
    set hive.vectorized.execution.enabled = false;
    INSERT OVERWRITE TABLE dwd_log_info_di_emr PARTITION (dt='${bizdate}')
    SELECT ip
      , uid
      , tm
      , status
      , bytes 
      , getregion(ip) AS region --Use custom UDF to derive region from IP. 
      , regexp_extract(request, '(^[^ ]+) .*') AS method --Split request into three fields using regex.
      , regexp_extract(request, '^[^ ]+ (.*) [^ ]+$') AS url
      , regexp_extract(request, '.* ([^ ]+$)') AS protocol 
      , regexp_extract(referer, '^[^/]+://([^/]+){1}') AS referer  --Clean referer using regex to get a more precise URL.
      , CASE
        WHEN lower(agent) RLIKE 'android' THEN 'android' --Derive device type and access pattern from agent.
        WHEN lower(agent) RLIKE 'iphone' THEN 'iphone'
        WHEN lower(agent) RLIKE 'ipad' THEN 'ipad'
        WHEN lower(agent) RLIKE 'macintosh' THEN 'macintosh'
        WHEN lower(agent) RLIKE 'windows phone' THEN 'windows_phone'
        WHEN lower(agent) RLIKE 'windows' THEN 'windows_pc'
        ELSE 'unknown'
      END AS device
      , CASE
        WHEN lower(agent) RLIKE '(bot|spider|crawler|slurp)' THEN 'crawler'
        WHEN lower(agent) RLIKE 'feed'
        OR regexp_extract(request, '^[^ ]+ (.*) [^ ]+$') RLIKE 'feed' THEN 'feed'
        WHEN lower(agent) NOT RLIKE '(bot|spider|crawler|feed|slurp)'
        AND agent RLIKE '^[Mozilla|Opera]'
        AND regexp_extract(request, '^[^ ]+ (.*) [^ ]+$') NOT RLIKE 'feed' THEN 'user'
        ELSE 'unknown'
      END AS identity
      FROM (
        SELECT SPLIT(col, '##@@')[0] AS ip
        , SPLIT(col, '##@@')[1] AS uid
        , SPLIT(col, '##@@')[2] AS tm
        , SPLIT(col, '##@@')[3] AS request
        , SPLIT(col, '##@@')[4] AS status
        , SPLIT(col, '##@@')[5] AS bytes
        , SPLIT(col, '##@@')[6] AS referer
        , SPLIT(col, '##@@')[7] AS agent
        FROM ods_raw_log_d_emr
      WHERE dt = '${bizdate}'
    ) a;
  2. Configure the debug parameters.

    On the right side of the EMR Hive node editing page, click Run Configuration and configure the following parameters. These parameters are used for test runs in Step 4 by using the Run Configuration settings.

    Parameter

    Description

    Computing Resources

    Select the EMR compute resource that you associated in the environment preparation phase.

    Resource Group

    Select the serverless resource group that you purchased in the environment preparation phase.

    Script Parameters

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

  3. After the configuration is complete, click the image icon in the toolbar to save the task node.

Configure the dws_user_info_all_di_emr node

  1. Edit the node content.

    On the workflow orchestration page, hover over the EMR Hive node dws_user_info_all_di_emr and click Open Node that appears above the node. In the dialog that appears, select Save and Open to go to the EMR Hive node editing page. Enter the following sample SQL statements.

    --Create DW layer table
    CREATE TABLE IF NOT EXISTS dws_user_info_all_di_emr (
      uid STRING COMMENT 'User ID',
      gender STRING COMMENT 'Gender',
      age_range STRING COMMENT 'Age range',
      zodiac STRING COMMENT 'Zodiac sign',
      region STRING COMMENT 'Region, derived from IP',
      device STRING COMMENT 'Device type ',
      identity STRING COMMENT 'Access type: crawler feed user unknown',
      method STRING COMMENT 'HTTP request type',
      url STRING COMMENT 'URL',
      referer STRING COMMENT 'Referrer URL',
      `time` STRING COMMENT 'Time yyyymmddhh:mi:ss'
    )
    PARTITIONED BY (
      dt STRING
    );
    
    ALTER TABLE dws_user_info_all_di_emr ADD IF NOT EXISTS PARTITION (dt='${bizdate}');
    
    INSERT OVERWRITE TABLE dws_user_info_all_di_emr PARTITION (dt='${bizdate}')
    SELECT COALESCE(a.uid, b.uid) AS uid
      , b.gender
      , b.age_range
      , b.zodiac
      , a.region
      , a.device
      , a.identity
      , a.method
      , a.url
      , a.referer
      , a.`time`
    FROM (
      SELECT *
      FROM dwd_log_info_di_emr
      WHERE dt = '${bizdate}'
    ) a
    LEFT OUTER JOIN (
      SELECT *
      FROM ods_user_info_d_emr
      WHERE dt = '${bizdate}'
    ) b
    ON a.uid = b.uid;
  2. Configure the debug parameters.

    On the right side of the EMR Hive node editing page, click Run Configuration and configure the following parameters. These parameters are used for test runs in Step 4 by using the Run Configuration settings.

    Parameter

    Description

    Computing Resources

    Select the EMR compute resource that you associated in the environment preparation phase.

    Resource Group

    Select the serverless resource group that you purchased in the environment preparation phase.

    Script Parameters

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

  3. After the configuration is complete, click the image icon in the toolbar to save the task node.

Configure the ads_user_info_1d_emr node

  1. Edit the node content.

    On the workflow orchestration page, hover over the EMR Hive node ads_user_info_1d_emr and click Open Node that appears above the node. In the dialog that appears, select Save and Open to go to the EMR Hive node editing page. Enter the following sample SQL statements.

    --Create RPT layer table
    CREATE TABLE IF NOT EXISTS ads_user_info_1d_emr (
      uid STRING COMMENT 'User ID',
      region STRING COMMENT 'Region, derived from IP',
      device STRING COMMENT 'Device type ',
      pv BIGINT COMMENT 'PV',
      gender STRING COMMENT 'Gender',
      age_range STRING COMMENT 'Age range',
      zodiac STRING COMMENT 'Zodiac sign'
    )
    PARTITIONED BY (
      dt STRING
    );
    
    ALTER TABLE ads_user_info_1d_emr ADD IF NOT EXISTS PARTITION (dt='${bizdate}');
    
    INSERT OVERWRITE TABLE ads_user_info_1d_emr PARTITION (dt='${bizdate}')
    SELECT uid
      , MAX(region)
      , MAX(device)
      , COUNT(0) AS pv
      , MAX(gender)
      , MAX(age_range)
      , MAX(zodiac)
    FROM dws_user_info_all_di_emr
    WHERE dt = '${bizdate}'
    GROUP BY uid;
  2. Configure the debug parameters.

    On the right side of the EMR Hive node editing page, click Run Configuration and configure the following parameters. These parameters are used for test runs in Step 4 by using the Run Configuration settings.

    Parameter

    Description

    Computing Resources

    Select the EMR compute resource that you associated in the environment preparation phase.

    Resource Group

    Select the serverless resource group that you purchased in the environment preparation phase.

    Script Parameters

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

  3. After the configuration is complete, click the image icon in the toolbar to save the task node.

Step 4: Process data

  1. 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.

  2. Verify the data processing 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. In the left-side navigation pane of the Data Studio page, click image to go to the DataStudio page. In the left-side directory tree, select Project Directory.

    3. Right-click the work directory that you created, choose Create Node... > EMR > EMR Hive, specify a custom EMR Hive node name, and click Confirm to create the node.

    4. 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.

      Note

      The partition column dt in the query statement must be updated to the actual business date. For example, if the task runs on 20250223, the business date is 20250222, 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 dt partition. 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.

Note

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.

  1. In the left-side navigation pane of Data Studio, click image. In the Project Directory section, find the workflow you created and click it to open the workflow dashboard.

  2. In the toolbar at the top of the page, click Publish to open the deployment panel.

  3. 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.

  1. After the tasks are deployed, click Operation and Maintenance Center in the upper-right corner.

    Alternatively, click the Icon icon in the upper-left corner and choose All Products > Data Development and O&M > Operation and Maintenance Center (Workflow).

  2. In the left-side navigation pane, choose Auto Triggered Task O&M > Auto Triggered Node to go to the Auto Triggered Node page, and click the workshop_start_emr virtual node.

  3. In the DAG on the right side, right-click the workshop_start_emr node and choose Supplementary data > Current and Descendant Nodes Retroactively.

  4. Select the tasks for which you want to backfill data, set the business date, and click Submit and Redirect.

  5. On the backfill data page, click Refresh until all tasks run successfully.

Note

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.