| --- |
| id: offline-compute_PySpark_pyspark_012 |
| name: 网页解析结果Top500详情统计 |
| category: offline-compute/PySpark |
| timeout_seconds: 900 |
| modality: pure-text |
| engine: pyspark |
| --- |
| ## Prompt |
| 我需要你生成一段 PySpark 代码,对网页解析结果进行质量统计,产出 Top500 站点的详情日报表。 |
|
|
| **业务背景与目标**:每天都会对大量网页进行解析,解析结果记录在 `ai_engine_classify_parse_result_daily` 表中。安全部门需要按站点维度统计解析质量,包括成功/失败解析数、索引页占比、短内容占比、各错误步骤分布等,并与站点优先级信息关联,生成一张按日期和站点粒度的解析质量详情表。 |
|
|
| **输入表**: |
| - `internal_platform_db.sec_app_hy_top_500_sites_tag_v1_pyspark_100` |
| - `internal_platform_db.ai_engine_classify_parse_result_daily_pyspark_100` |
|
|
| **数据范围与过滤条件**: |
| - 运行日期 today_str 固定为 '20260513' |
| - 数据范围:date_key 从 '20260508' 到 '20260513'(最近 5 天) |
|
|
| **计算规则**: |
| 1. 从 parse_html JSON 字段中提取 content 字段(使用 from_json + schema_of_json) |
| 2. 计算 content_length = length(content) |
| 3. 按 (date_key, host, fld) 分组聚合: |
| - 成功解析数 successful_parses、失败解析数 failed_parses、总解析数 total_parses |
| - 索引页数 index_page_count(web_type='索引页')、索引页比例 index_page_count_rate = index_page_count/total_parses |
| - 短内容数 short_content_count(content_length < 50)、短内容比例 short_content_count_rate = short_content_count/successful_parses |
| - 各错误步骤计数:error_step_1_count、error_step_2_count、error_step_3_count |
| 4. LEFT JOIN 关联 priority_info:匹配条件为 source_fld = priority_info.fld OR source_host = priority_info.host |
| 5. 去重:dropDuplicates(["date_key", "host", "fld", "priority", "successful_parses", "total_parses", "index_page_count"]) |
|
|
| **输出要求**: |
| - 目标表:`internal_platform_db.ai_engine_classify_parse_result_daily_detail_pyspark_100` |
| - 写入策略:先建表(ORC 存储,16 列),再使用 df.write.mode("overwrite").insertInto() 写入 |
| - 输出列:date_key, host, fld, is_host, priority, successful_parses, failed_parses, total_parses, index_page_count, index_page_count_rate, short_content_count, short_content_count_rate, error_step_1_count, error_step_2_count, error_step_3_count, error_info_list |
|
|