Data registration

Updated at:

This document describes the process of preparing and registering data for traffic control.

Data preparation

1. Real-time behavior data

1.1 Production environment

The service uses this topic to compute real-time traffic statistics for traffic control tasks.

1.2 Pre-production environment

The pre-production environment uses backend logs from the PAI-Rec recommendation engine as real-time behavior data. To enable this, add the following configuration to your engine settings. This configuration writes the backend logs to the pairec_debug_log_prepub topic in DataHub, which enables behavior statistics collection in the pre-production environment.

    "DatahubConfs": {
        "datahub_info": {
            "Endpoint": "http://dh-cn-shanghai-int-vpc.aliyuncs.com",
            "AccessId": "${AccessKey}",
            "AccessKey": "${AccessSecret}",
            "ProjectName": "demo_rec",
            "TopicName": "pairec_debug_log_prepub",
            "Schemas": [
                {
                    "Field": "request_id",
                    "Type": "string"
                },
                {
                    "Field": "module",
                    "Type": "string"
                },
                {
                    "Field": "scene_id",
                    "Type": "string"
                },
                {
                    "Field": "request_time",
                    "Type": "integer"
                },
                {
                    "Field": "exp_id",
                    "Type": "string"
                },
                {
                    "Field": "items",
                    "Type": "string"
                },
                {
                    "Field": "retrieveid",
                    "Type": "string"
                },
                {
                    "Field": "uid",
                    "Type": "string"
                }
            ]
        }
    }

2. User table

This table defines the scope of traffic affected by control tasks.

3. Item table

In MaxCompute, prepare two identical item tables, item_table and item_table_prepub. For each table, register a feature view in FeatureStore: one for the production environment and one for the pre-production environment.

3.1 Proportional control

The item table must include the item ID and item selection feature fields.

3.2 Volume or count control

The item table must include the item ID, a feature field for the controlled item (is_control), and a field that indicates whether the control target is met (is_complated).

Data registration

1. Behavior table

On the data registration page, set the table type to behavior table. Set the data table name to behavior and the data source type to DataHub. Enter the project name and select behavior for the Topic. In the field settings area, you can batch import fields using Import from JSON. The imported fields, such as app_version, camp_id, camp_name, camp_type, request_id, scene, start_time, and user_id, must all be of the STRING type. In the key field mapping, set the user_id field to user_id, the item_id field to item_id, and the event_type field to event. In the behavior settings, map behavior values to their corresponding names: expose to exposure, click to click, and like to like.

2. Item table

On the data registration page, set the table type to item table. Configure the data table name, for example, item_1500_v1_online. Select the FeatureStore project, set the feature entity to item, and select the corresponding feature view version, such as home_feed_new_item_1500_v2. In the item selection feature section, configure fields, including item_id (STRING type) and the is_1500_new_item field, labeled as Featured Items.

The registration process for the item table in the pre-production environment is the same. Add the _prepub suffix to the data table name, for example, item_1500_v1_online_prepub. Use the pre-production version of the feature view, such as home_feed_new_item_1500_v2_prepub. The item selection feature field is labeled as Featured New Items.

3. User table

On the data registration page, set the table type to user table. Configure the data table name as user_table. Select the FeatureStore project, set the feature entity to user, and enter the feature view ID. In the user profile features section, configure user feature fields, such as gender (STRING type).

Other operations

In a standard recall path, items that are controlled by volume or count may not be fully retrieved. To address this, you must create a separate recall table and a dedicated recall process. To improve recall efficiency, exclude items from retrieval once they meet their control target. To achieve this, update the is_complated field in the recall table every 30 minutes to reflect the target completion status.

1. Synchronize behavior data

Write the real-time behavior data from the DataHub topics rec_sln_demo_behavior_table_v1 and pairec_debug_log_prepub to the MaxCompute tables rec_sln_demo_behavior_table_json_online_v1 and pairec_debug_log_prepub.

  1. Log in to DataHub and navigate to the topic list for the behavior table.

  2. Click Sync and create a new MaxCompute connector.

  3. After you enter the required information, click Create.

2. Recall table update

  1. In DataWorks, create a new ODPS SQL node to calculate the number of exposures and update the is_complated field. Schedule this node to run every 30 minutes.

INSERT OVERWRITE TABLE item_table PARTITION (ds = '${bdp.system.bizdate}')
WITH tmp_a AS 
(
    SELECT item_id
    FROM   item_table
    WHERE  ds = '${bdp.system.bizdate}'
)
,tmp_b AS 
(
    SELECT  *
    FROM  (
            SELECT item_id
                   ,COUNT(*) cnt
            FROM (
                    SELECT  CAST(GET_JSON_OBJECT(content,'$.item_id') AS BIGINT) item_id
                            ,GET_JSON_OBJECT(content,'$.exp_id') exp_id
                            ,GET_JSON_OBJECT(content,'$.request_id') request_id
                    FROM    rec_sln_demo_behavior_table_json_online_v1
                    WHERE   ds = TO_CHAR(DATEADD(TO_DATE('${bdp.system.bizdate}','yyyymmdd'),+1,'dd'),'yyyymmdd')
                    AND     GET_JSON_OBJECT(content,'$.request_id') != ''
                ) 
            GROUP BY item_id
          ) 
    WHERE cnt > 30
)SELECT a.item_id
        ,CASE WHEN b.item_id IS NOT NULL THEN 0
              ELSE 1
        END AS is_complated
FROM tmp_a a
LEFT JOIN tmp_b b
ON a.item_id = b.item_id
;

INSERT OVERWRITE TABLE item_table_prepub PARTITION (ds = '${bdp.system.bizdate}')
WITH tmp_a AS 
(
    SELECT  item_id
    FROM    item_table_prepub
    WHERE   ds = '${bdp.system.bizdate}'
)
,tmp_b AS 
(
    SELECT  *
    FROM    (
                SELECT  item_id
                        ,COUNT(*) cnt
                FROM    (
                            SELECT  `request_id`
                                    ,SPLIT_PART(col1_new,':',1) AS item_id
                                    ,exp_id
                            FROM    pairec_debug_log_prepub
                            LATERAL VIEW EXPLODE(SPLIT(`items`,'},')) adTable AS col1_new
                            WHERE   `module` = 'recommend'
                            AND     ds = TO_CHAR(DATEADD(TO_DATE('${bdp.system.bizdate}','yyyymmdd'),+1,'dd'),'yyyymmdd')
                        ) 
                GROUP BY item_id
            ) 
    WHERE   cnt > 30
)SELECT  a.item_id
        ,CASE   WHEN b.item_id IS NOT NULL THEN 0
                ELSE 1
        END AS is_complated
FROM    tmp_a a
LEFT JOIN tmp_b b
ON      a.item_id = b.item_id
;
  1. Synchronize the item_table and item_table_prepub tables to Hologres for recall. In FeatureStore, click data synchronization, paste the synchronization code, and deploy it to DataWorks. Schedule the task to run every 30 minutes.

In the feature view list in FeatureStore, find the target feature view, such as home_feed_new_item_1500_v2, and click data synchronization on the right.

On the DataWorks data synchronization task configuration page, select Cluster or exclusive resource group as the run mode. In the code editor, paste the synchronization code provided by FeatureStore, and then deploy the task.