dicemy's picture
Upload 655 files
e8c001c verified
|
Raw
History Blame Contribute Delete
3.68 kB
metadata
id: offline-compute_HiveSQL_hivesql_018
name: >-
  Compute scores for first-level comments from view records and comment logs.
  Group by recall_uin + channel_id + fe
category: offline-compute/HiveSQL
timeout_seconds: 600
modality: pure-text
engine: hivesql

Prompt

Task Objective: Compute the composite score for first-level comments newly added by recalled read users after their first post view, for content heat analysis.

Inputs:

  • internal_platform_db.dws_social_group_content_forum_hot_feed_recall_feed_view_hi_query_engine_122 (view records, filter imp_hour within [2026060811, 2026060910])
  • internal_platform_db.dwd_social_group_content_forum_hot_feed_recall_comment_log_hi_query_engine_122 (comment logs, filter imp_hour within [2026060811, 2026060910])
  • internal_platform_db.dwd_all_social_group_user_slice_ds_query_engine_122 (user identity, filter imp_date >= 20260607)

Processing Rules:

  1. Build a view aggregation: From the view table, aggregate by uin + channel_id + feed_id, extracting the first/last view time, detail page view count, and duration.
  2. Filter comments: Join the comment log with the view aggregation on channel_id + feed_id, keeping only records where the comment time is >= the first view time.
  3. Enrich user identity: Left join the user table, using member_role as a fallback for user_type (use the original user_type when missing).
  4. Compute first-level comment metrics: Group by recall_uin + channel_id + feed_id + p_comment_id (as the first-level comment ID) + uin, and compute:
    • Normal user like count (action_type='comment_like' AND user_type=0)
    • Author like count (action_type='comment_like' AND uin=author_uin)
    • Channel owner like count (action_type='comment_like' AND user_type in (1,2))
    • Normal user reply count (action_type='comment' AND comment_type='comment_reply' AND user_type=0 AND uin<>comment_uin)
    • Author reply count (action_type='comment' AND comment_type='comment_reply' AND uin=author_uin AND uin<>comment_uin)
    • Channel owner reply count (action_type='comment' AND comment_type='comment_reply' AND user_type in (1,2) AND uin<>comment_uin)
  5. Aggregate by recall_uin + channel_id + feed_id + comment_id to compute deduplicated UV and totals:
    • UV (count distinct of users with the behavior) and counts for each like/reply type
    • Normal user average reply count (total replies / number of users who replied)
  6. Compute scores (tiered rules):
    • Normal user like score: tiered by count (1→2, 2–4→4, 5–10→7, 11–20→8, 21–50→10, >50→12)
    • Author like score: tiered by UV, then +2
    • Channel owner like score: tiered by count, then +1
    • Normal user reply score: when count < 4, UV2.5 (cap 30); when >= 4, UV2 (cap 30)
    • Author reply score: normal user reply score + 3
    • Channel owner reply score: normal user reply score + 1
    • Average reply score: mean <=1.5→0, 1.5–3→3, >3→6
    • Total comment score: sum of the above 7 score components

Output Requirements:

  • Field order: imp_hour, uin (i.e., recall_uin), channel_id, feed_id, comment_id, comment_time, comment_score, and the scores, UVs, and counts for each like/reply type (20 metric fields in total)
  • comment_time takes the last comment time of that comment
  • Partition field imp_hour is fixed as 2026060910

Write Requirements:

  • Output table: internal_platform_db.dws_social_group_content_forum_hot_feed_recall_comment_score_hi_cand_query_engine_122
  • Write method: INSERT OVERWRITE partition imp_hour=2026060910

Please write the final HiveSQL to result.sql and execute it.