This topic describes how to process the user information table ods_user_info_d_odps and access log data ods_raw_log_d_odps synchronized to MaxCompute in DataWorks MaxCompute nodes to produce user profile data. It shows how to use DataWorks and MaxCompute to compute and analyze synchronized data in a simple data warehouse processing scenario.
Prerequisites
Before starting, complete the steps in Synchronize data.
-
You have used Data Integration to synchronize basic user information from MySQL,
ods_user_info_d, to the MaxComputeods_user_info_d_odpstable. -
You have used Data IntegrationYou have also synchronized website access logs stored in OSS,
user_log.txt, to the MaxComputeods_raw_log_d_odpstable.
Goal
This section processes ods_user_info_d_odps and ods_raw_log_d_odps synchronized to MaxCompute to produce a basic user profile table.
-
Process the log table
ods_raw_log_d_odpsby splitting log information into fields and producing the detailed log tabledwd_log_info_di_odps. -
Join the detailed log table
dwd_log_info_di_odpswith the user table on uid to produce the aggregated user log tableods_user_info_d_odpsanddws_user_info_all_di_odps. -
dws_user_info_all_di_odpshas many fields. To use it for data consumption, process it further intoads_user_info_1d_odpstable.
Open Data Development
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 Data Development.
I. Design the workflow
In the Synchronize data stage, data was synchronized to MaxCompute. Next, process it to produce basic user profile data.
-
Nodes at each layer and their logic.
In the business process canvas, click Create Node to create these data processing nodes.
Node category
Node type
Node name
(named after the output table)
Code logic
MaxCompute
ODPS SQL
dwd_log_info_di_odpsUse built-in or custom functions to split raw log
ods_raw_log_d_odpsdata and write it to multipledwd_log_info_di_odpsfields in the table.MaxCompute
ODPS SQL
dws_user_info_all_di_odpsAggregate basic user information and and preliminarily processed logs into one table.
MaxCompute
ODPS SQL
ads_user_info_1d_odpsFurther process the data to produce a basic user profile.
-
Workflow DAG.
Drag node components into the business process canvas and connect them to set upstream and downstream dependencies for data processing.

II. Configure the business process
Create MaxCompute tables
Create dwd_log_info_di_odps, dws_user_info_all_di_odps, ads_user_info_1d_odps tables to store each layer’s processed data. The following steps create the tables quickly. For more MaxCompute table operations, see Create and use MaxCompute tables.
-
Open Create Table.
In the DataStudioOn the Synchronize data page, open the business process WorkShop. Right-click MaxCompute and select Create Table.
-
Define the MaxCompute table schema.
In the Create TableIn the dialog box, enter the table name and click Create. Create these three tables:
dwd_log_info_di_odps,dws_user_info_all_di_odps,ads_user_info_1d_odps. Select DDL to create them with DDL. Use the statements below. -
Commit the definitions to the engine.
After defining each table, click Commit to Development Environment and Commit to Production Environment, . The system creates the physical tables in the MaxCompute projects for the development and production environments.
-
Commit the table to the DataWorks development environment, creating it in development MaxCompute.
-
Commit the table to DataWorks production, creating it in production MaxCompute.
Note-
For a basic-mode workspace, commit the table only to production. For basic and standard modes, see Workspace mode differences.
-
For the relationship between DataWorks and MaxCompute projects in each environment, see DataWorks on MaxCompute.
-
-
Create dwd_log_info_di_odps
Double-click the dwd_log_info_di_odps table and click DDL in its editor, then enter this CREATE TABLE statement.
CREATE TABLE IF NOT EXISTS dwd_log_info_di_odps (
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 method',
url STRING COMMENT 'url',
protocol STRING COMMENT 'HTTP protocol version',
referer STRING COMMENT 'Referrer URL',
device STRING COMMENT 'Device type ',
identity STRING COMMENT 'Visit type: crawler, feed, user, or unknown'
)
PARTITIONED BY (
dt STRING
)
LIFECYCLE 14;
Create dws_user_info_all_di_odps
Double-click dws_user_info_all_di_odps and click DDL in its editor, then enter this CREATE TABLE statement.
CREATE TABLE IF NOT EXISTS dws_user_info_all_di_odps (
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 'Visit type: crawler, feed, user, or unknown',
method STRING COMMENT 'HTTP request method',
url STRING COMMENT 'url',
referer STRING COMMENT 'Referrer URL',
time STRING COMMENT 'Time yyyymmddhh:mi:ss'
)
PARTITIONED BY (
dt STRING
)
LIFECYCLE 14;
Create ads_user_info_1d_odps
Double-click ads_user_info_1d_odps and click DDL in its editor, then enter this CREATE TABLE statement.
CREATE TABLE IF NOT EXISTS ads_user_info_1d_odps (
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
)
LIFECYCLE 14;
Create the getregion function
To process the synchronized Structure of log data for the experiment, you need a function to parse IP addresses into regions. This tutorial provides the required resource. Download it locally, upload it to the DataWorks workspace, then register the function.
This sample IP resource is only for the tutorial. For production IP-to-location mapping, use a specialist IP service.
-
Upload ip2region.jar.
-
Download ip2region.jar.
Noteip2region.jarThis resource is an example for the tutorial only. -
In the DataStudioOpen the WorkShop business process page. Right-click MaxCompute and select .
-
Click Upload and select the downloaded ip2region.jar, then click Open.
Note-
Select Upload to ODPS.
-
The resource name need not match the uploaded file name.
-
-
Click the toolbar
button to commit the resource to the development MaxCompute project.
-
-
Register getregion.
-
Open the function registration page.
In the DataStudioOpen the business process on the MaxCompute and select Create Function.
-
Enter a function name.
In the Create FunctionIn the dialog box, enter Function Name
getregionand click Create. -
In the Register FunctionIn the dialog box, configure these parameters.
Parameter
Description
Function Type
Select a function type.
MaxCompute Engine Instance
The default cannot be changed.
Function Name
The name entered when creating the function.
Owner
Select an owner.
Class Name
Enter
org.alidata.odps.udf.Ip2Region.Resources
Enter
ip2region.jar.Description
Enter an IP address to convert to a region.
Expression Syntax
Enter
getregion('ip').Parameter Description
Enter an IP address.
-
Click
button to commit the function to the development engine.
-
Configure MaxCompute processing nodes
Use ODPS SQL scheduling to implement processing at each layer. The nodes have strong lineage dependencies, and the synchronization stage manually added the output table of the synchronization task as the node output. Therefore, DataWorks uses automatic parsing to configure processing task dependencies from lineage.
Configure the dwd_log_info_di_odps node
In the business process canvas, double-click dwd_log_info_di_odps. Write SQL that uses the new function to process the upstream table ods_raw_log_d_odps field and writes results to the dwd_log_info_di_odps table. Example processing:Appendix: Processing examples.
-
Edit code.
-- Scenario: Use getregion and regular expressions to parse raw log IP addresses and fields, then write analyzable fields to dwd_log_info_di_odps. -- This example provides getregion to map IP addresses to regions. -- Additional information: -- 1. Before using a function in a DataWorks node, upload its resource and register the function in the visual interface. -- The getregion resource in this example is ip2region.jar. -- 2. DataWorks scheduling parameters let you write daily incremental data to the matching business partition. -- In development, define code variables as ${variable_name} and assign scheduling parameters to them on the scheduling page to pass dynamic values to code. INSERT OVERWRITE TABLE dwd_log_info_di_odps PARTITION (dt='${bizdate}') SELECT ip , uid , time , status , bytes , getregion(ip) AS region --Use a custom UDF to derive the region from IP. , regexp_substr(request, '(^[^ ]+ )') AS method --Split request into three fields with a regular expression. , regexp_extract(request, '^[^ ]+ (.*) [^ ]+$') AS url , regexp_substr(request, '([^ ]+$)') AS protocol , regexp_extract(referer, '^[^/]+://([^/]+){1}') AS referer --Parse referer with a regular expression to obtain a more precise URL. , CASE WHEN TOLOWER(agent) RLIKE 'android' THEN 'android' --Derive device and visit type from agent. WHEN TOLOWER(agent) RLIKE 'iphone' THEN 'iphone' WHEN TOLOWER(agent) RLIKE 'ipad' THEN 'ipad' WHEN TOLOWER(agent) RLIKE 'macintosh' THEN 'macintosh' WHEN TOLOWER(agent) RLIKE 'windows phone' THEN 'windows_phone' WHEN TOLOWER(agent) RLIKE 'windows' THEN 'windows_pc' ELSE 'unknown' END AS device , CASE WHEN TOLOWER(agent) RLIKE '(bot|spider|crawler|slurp)' THEN 'crawler' WHEN TOLOWER(agent) RLIKE 'feed' OR regexp_extract(request, '^[^ ]+ (.*) [^ ]+$') RLIKE 'feed' THEN 'feed' WHEN TOLOWER(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 time , 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_odps WHERE dt ='${bizdate}' ) a; -
Configure scheduling properties.
On the configuration page, click Schedule on the right to open the Scheduling Settings panel for scheduling and node settings. For details, see Node scheduling configuration. Configure:
Setting
Value
Illustration
Scheduling Parameter
In the Scheduling ParameterParameter settings:
-
Parameter name:
bizdate. -
Parameter Value:
$[yyyymmdd-1].
The scheduling parameter panel shows the parameter bizdate with value $[yyyymmdd-1], sourced from code parsing. At the bottom is the Scheduling Parameter Preview button.
Schedule
-
Scheduling period:
Day. -
Scheduling Time:
00:30. -
RUN Attribute: Allows the task to be rerun regardless of its previous success or failure.
Use the default values for other parameters.
NoteThe node runs only after 00:30 every day.
The time properties panel shows instance generation as T+1, generated the following day, scheduling type as Normal Scheduling, cycle as Day, scheduled time as 00:30, rerun property as Rerun after success or failure, and effective date as Always Effective.
Resource Group
Select the Prepare the environment Serverless resource group created earlier.
The resource properties panel shows the scheduling resource group as User_portraits (use the name of the Serverless resource group you created).
Dependencies
Through automatic code parsing, DataWorks sets the node that produces data for table
ods_raw_log_d_odps(ods_raw_log_d_odps) as an upstream dependency of the current nodedwd_log_info_di_odps. It sets tabledwd_log_info_di_odpsas this node’s output, so downstream nodes that query the table automatically depend on this node.In the scheduling dependencies panel, automatic parsing before commit is set to Yes. Upstream nodes are Parse Inputs and Outputs from Code and are configured as ods_raw_log_d_odps. Node outputs include system default, manually added, and parsed entries.
NoteUpstream dependencies: Click Parse Code Inputs and Outputs to find the upstream node whose output is
MaxCompute production project name.table name.Output Name of Ancestor Node.Node output name: Click Parse Code Inputs and Outputs: Click to parse table names in the code and generate this node’s output name in the
MaxCompute production project name.table nameformat for downstream nodes. -
-
Configure any other required settings. Then click
in the node editor toolbar to save.
Configure the dws_user_info_all_di_odps node
In the business process canvas, double-click dws_user_info_all_di_odps. Write SQL to join the upstream tables dwd_log_info_di_odps and ods_user_info_d_odps and write to the dws_user_info_all_di_odps table.
-
Edit code.
-- Scenario: Combine processed logs in dwd_log_info_di_odps with user data in ods_user_info_d_odps and write to dws_user_info_all_di_odps. -- Additional information:DataWorks scheduling parameters let you write daily incremental data to the matching business partition. -- In development, define code variables as ${variable_name} and assign scheduling parameters to them on the scheduling page to pass dynamic values to code. INSERT OVERWRITE TABLE dws_user_info_all_di_odps 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_odps WHERE dt = '${bizdate}' ) a LEFT OUTER JOIN ( SELECT * FROM ods_user_info_d_odps WHERE dt = '${bizdate}' ) b ON a.uid = b.uid; -
Configure scheduling properties.
On the configuration page, click Schedule on the right to open the Scheduling Settings panel for scheduling and node settings. For details, see Node scheduling configuration. Configure:
Setting
Value
Illustration
Scheduling Parameter
In the Scheduling ParameterParameter settings:
-
Parameter name:
bizdate -
Parameter Value:
$[yyyymmdd-1]
The scheduling parameter panel shows the parameter bizdate with value $[yyyymmdd-1], sourced from code parsing. At the bottom is the Scheduling Parameter Preview button.
Schedule
-
Scheduling period:
Day. -
Scheduling Time:
00:30. -
RUN Attribute: Allows the task to be rerun regardless of its previous success or failure.
Use the default values for other parameters.
NoteThe node runs only after 00:30 every day.
The time properties panel shows instance generation as T+1, generated the following day, scheduling type as Normal Scheduling, cycle as Day, scheduled time as 00:30, rerun property as Rerun after success or failure, and effective date as Always Effective.
Resource Group
Select the Prepare the environment Serverless resource group created earlier.
The resource properties panel shows the scheduling resource group as User_portraits (use the name of the Serverless resource group you created).
Dependencies
Automatic code parsing identifies the nodes that produce data for tables
dwd_log_info_di_odpsandods_user_info_d_odps:dwd_log_info_di_odpsandods_user_info_d_odps. It sets them as upstream dependencies of the current nodedws_user_info_all_di_odps. It also sets the output tabledws_user_info_all_di_odpsas this node’s output, so downstream nodes that query the table automatically depend on this node.Configure dependencies as for dwd_log_info_di_odps. Code parsing sets upstream nodes to ods_user_info_d_odps and dwd_log_info_di_odps. The node output includes dws_user_info_all_di_odps.
NoteUpstream dependencies: Click Parse Code Inputs and Outputs to find the upstream node whose output is
MaxCompute production project name.table name.Output Name of Ancestor Node.Node output name: Click Parse Code Inputs and Outputs: Click to parse table names in the code and generate this node’s output name in the
MaxCompute production project name.table nameformat for downstream nodes. -
-
Configure any other required settings. Then click
in the node editor toolbar to save.
Configure the ads_user_info_1d_odps node
In the business process canvas, double-click ads_user_info_1d_odpsDouble-click the node and write SQL to process the upstream dws_user_info_all_di_odps table and write the result to ads_user_info_1d_odps table.
-
Edit code.
-- Scenario: Process the user access wide table dws_user_info_all_di_odps into a basic user profile in ads_user_info_1d_odps. -- Additional information:DataWorks scheduling parameters let you write daily incremental data to the matching business partition. -- In development, define code variables as ${variable_name} and assign scheduling parameters to them on the scheduling page to pass dynamic values to code. INSERT OVERWRITE TABLE ads_user_info_1d_odps 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_odps WHERE dt = '${bizdate}' GROUP BY uid; -
Configure scheduling properties.
On the configuration page, click Schedule on the right to open the Scheduling Settings panel for scheduling and node settings. For details, see Node scheduling configuration. Configure:
Setting
Value
Illustration
Scheduling Parameter
In the Scheduling ParameterParameter settings:
-
Parameter name:
bizdate. -
Parameter Value:
$[yyyymmdd-1].
The scheduling parameter panel shows the parameter bizdate with value $[yyyymmdd-1], sourced from code parsing. At the bottom is the Scheduling Parameter Preview button.
Schedule
-
Scheduling period:
Day. -
Scheduling Time:
00:30. -
RUN Attribute: Allows the task to be rerun regardless of its previous success or failure.
Use the default values for other parameters.
NoteThe node runs only after 00:30 every day.
The time properties panel shows instance generation as T+1, generated the following day, scheduling type as Normal Scheduling, cycle as Day, scheduled time as 00:30, rerun property as Rerun after success or failure, and effective date as Always Effective.
Resource Group
Select the Prepare the environment Serverless resource group created earlier.
The resource properties panel shows the scheduling resource group as User_portraits (use the name of the Serverless resource group you created).
Dependencies
Through automatic code parsingAutomatically configure dependencies from node lineage. Set the node producing
dws_user_info_all_1d_odpstable data asdws_user_info_all_1d_odpsan upstream dependency of the current nodeads_user_info_1d_odpsas an upstream dependency. Set the node output table ads_user_info_1d as this node’s output for downstream queries.Configure dependencies as above. Code parsing sets the upstream node to dws_user_info_all_di_odps. The node output includes ads_user_info_1d_odps.
NoteUpstream dependencies: Click Parse Code Inputs and Outputs to find the upstream node whose output is
MaxCompute production project name.table name.Output Name of Ancestor Node.Node output name: Click Parse Code Inputs and Outputs: Click to parse table names in the code and generate this node’s output name in the
MaxCompute production project name.table nameformat for downstream nodes. -
-
Configure any other required settings. Then click
in the node editor toolbar to save.
III. Run the business process
Run the business process
-
In the On the Data Development page, double-click Workflow under
User Profile Analysis_MaxComputeto open the workflow canvas. Click the toolbar
icon to run nodes according to their dependencies.After the run, nodes execute in dependency order. A green success icon appears next to each node.
-
Check execution:
-
Task status: A node in
status indicates that synchronization ran successfully. -
Task logs: Right-click a node and select View Logs to view its development environment log.
-
View synchronization results
After all tasks reach
status, query the final processed table.
-
On the DataStudio page, click
in the left navigation pane to open the Ad Hoc Query panel. -
Right-click Ad Hoc Query and select Create Node > ODPS SQL.
Run this SQL in an ODPS SQL node to check the final table:
//Set the partition filter to the actual business date. If the task runs on 20230222, the business date is 20230221, the previous day. select count(*) from ads_user_info_1d_odps where dt='BUSINESS_DATE';NoteThis tutorial runs in DataStudio (development environment), so data is written by default to the specified table in its corresponding engine project, workshop2024_01_dev.
IV. Publish the business process
Publish the tasks to production for automatic scheduling.
Commit to development
On the business process toolbar, click
to commit all tasks. Configure as follows and click Confirm.
In the CommitIn the dialog box, select all nodes (workshop_start_odps, ods_raw_log_d_odps, ods_user_info_d_odps, dwd_log_info_di_odps, and dws_user_info_all_di_odps). Enter Change Description (for example, “User Profile Analysis MaxCompute Edition”), select Ignore warnings about mismatched output on hold and click Confirm.
Publish to production
Committing the business process places tasks in development. Development tasks are not scheduled automatically; publish them to production.
-
On the business process toolbar, click
or click the DataStudio page Task Publishing button to open the Create Deploy Task page. -
Publish the target tasks and related resources and functions in batches.
In the Create Publish PackageOn the Business ProcessSelect the User Profile Analysis_MaxCompute page, the list shows all tasks to publish, including ODPS SQL nodes, batch synchronization nodes, the workshop_start_odps virtual node, getregion, and ip2region.jar. All have status Passed Checks. Select all and click Publish Selected.
V. Scheduling and operations
In production, backfill historical data as needed. This tutorial uses Backfill Data to demonstrate operations. For more features, see Operation Center.
-
Open Operation Center.
After publishing succeeds, click the upper-right Operation Center.
You can also open the business process editor and click the toolbar Go to O&M in the left navigation pane to open the Operation Center page.
-
Backfill a periodic task.
-
In the left navigation pane, click in the left navigation pane to open the Auto Triggered Task page, click the root node
workshop_start_odps. -
Right-click
workshop_start_odpsand select . -
Select all downstream nodes of
workshop_start_odps, enter a business date, and click Determine. The console opens Backfill Data page.In the periodic task DAG in Operation Center, right-click the workshop_start_odps node for a menu that includes Expand Child Nodes (to view downstream nodes by level), View Run Logs, Rerun, Rerun Downstream, and other operations.
-
-
Click Refresh until all SQL tasks succeed.
To avoid ongoing costs after the tutorial, you can set the node Scheduling Validity Period or Freeze the root virtual node of the business process (workshop_start_odps).
Next steps
After publishing, the workflow is complete. View the created tables, consume their data, or configure Data Quality monitoring. For details, see Manage data, Data service APIs, Data visualization and Monitor data quality.
Appendix: Processing examples
-
Before processing
58.246.10.82##@@2d24d94f14784##@@2014-02-12 13:12:25##@@GET /wp-content/themes/inove/img/feeds.gif HTTP/1.1##@@200##@@2572##@@http://coolshell.cn/articles/10975.html##@@Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36 -
After processing
For one sample record:time is 2014-02-12 13:12:25, status is 200, bytes is 2572, region is Shanghai (derived from IP by getregion), method is GET, protocol is HTTP/1.1, referer is coolshell.cn, device is windows_pc, and identity is feed.