# 从 internal_platform_db.dws_ug_app_ad_material_actio (HiveSQL)

## Prompt
任务目标：统计广告素材在各维度下的行为指标汇总，并生成一条更新日期记录。

输入：
- internal_platform_db.dws_ug_app_ad_material_action_di_query_engine_101

处理规则：
- 无 Join，单表处理
- 过滤条件：imp_date = 20260608
- 维度字段转换（使用 CASE WHEN）：
  - material_type: 1→'图片', 2→'视频'
  - source: 2→'人工素材', 3→'人机素材', 6→'AI素材'
  - video_model_type: 1→'镜头拆分模型(老模型)', 2→'剧情理解模型(新模型)'
  - create_type: 0→'无视频剪辑方式', 1→'高光剪辑', 2→'原始剪辑', 3→'拼合剪辑', 4→'二创剪辑', 5→'定点剪辑', 6→'拆条前贴', 7→'拆条剪辑', ELSE→'未知代码'+create_type
  - purpose: 1→'拉新', 2→'拉活', 3→'唤醒', 4→'收入', 5→'电商', 6→'当日拉活'
  - provider: 1→'AI侧', 2→'内部平台D侧'
- 分组维度：上述转换后的维度字段 + channel_name
- 聚合指标（均为 SUM）：product_flag→production_cnt, audit_flag→audit_cnt, pass_flag→pass_cnt, push_madia_flag→push_cnt, imp_madia_gdt_flag→imp_cnt, click_madia_gdt_flag→clck_cnt, imp_madia_cnt→imp, click_madia_cnt→clck
- 结果由两部分 UNION ALL 构成：第一部分为分组聚合结果，第二部分为一条 update_date=20260608 且其余字段均为 NULL 的记录

输出要求：
- 输出字段顺序：update_date, material_type_name, source_name, video_model_type_name, create_type_name, purpose_name, provider_name, production_cnt, audit_cnt, pass_cnt, push_cnt, imp_cnt, clck_cnt, imp, clck, channel_name, imp_date
- 不去重

写入要求：
- 目标表：internal_platform_db.ads_ug_app_ad_material_action_di_cand_query_engine_101
- 写入方式：INSERT OVERWRITE
- 分区：imp_date=20260608

请将最终 HiveSQL 写入 result.sql 并执行。

## Reference Solution
INSERT OVERWRITE TABLE internal_platform_db.ads_ug_app_ad_material_action_di_query_engine_101 PARTITION (imp_date=20260608)
            SELECT
                20260608 AS update_date
                , CASE
                    WHEN material_type = 1 THEN '图片'
                    WHEN material_type = 2 THEN '视频'
                END AS material_type_name
                , CASE
                    WHEN `source` = 2 THEN '人工素材'
                    WHEN `source` = 3 THEN '人机素材'
                    WHEN `source` = 6 THEN 'AI素材'
                END AS source_name
                , CASE
                    WHEN video_model_type = 1 THEN '镜头拆分模型(老模型)'
                    WHEN video_model_type = 2 THEN '剧情理解模型(新模型)'
                END AS video_model_type_name
                , CASE
                    WHEN create_type = 0 THEN '无视频剪辑方式'
                    WHEN create_type = 1 THEN '高光剪辑'
                    WHEN create_type = 2 THEN '原始剪辑'
                    WHEN create_type = 3 THEN '拼合剪辑'
                    WHEN create_type = 4 THEN '二创剪辑'
                    WHEN create_type = 5 THEN '定点剪辑'
                    WHEN create_type = 6 THEN '拆条前贴'
                    WHEN create_type = 7 THEN '拆条剪辑'
                    ELSE CONCAT('未知代码', create_type)
                END AS create_type_name
                , CASE
                    WHEN purpose = 1 THEN '拉新'
                    WHEN purpose = 2 THEN '拉活'
                    WHEN purpose = 3 THEN '唤醒'
                    WHEN purpose = 4 THEN '收入'
                    WHEN purpose = 5 THEN '电商'
                    WHEN purpose = 6 THEN '当日拉活'
                END AS purpose_name
                , CASE
                    WHEN `provider` = 1 THEN 'AI侧'
                    WHEN `provider` = 2 THEN '内部平台D侧'
                END AS provider_name
                , SUM(product_flag) AS production_cnt
                , SUM(audit_flag) AS audit_cnt
                , SUM(pass_flag) AS pass_cnt
                , SUM(push_madia_flag) AS push_cnt
                , SUM(imp_madia_gdt_flag) AS imp_cnt
                , SUM(click_madia_gdt_flag) AS clck_cnt
                , SUM(imp_madia_cnt) AS imp
                , SUM(click_madia_cnt) AS clck
                , channel_name
            FROM internal_platform_db.dws_ug_app_ad_material_action_di_query_engine_101
            WHERE imp_date = 20260608
            GROUP BY
                CASE
                    WHEN material_type = 1 THEN '图片'
                    WHEN material_type = 2 THEN '视频'
                END
                , CASE
                    WHEN `source` = 2 THEN '人工素材'
                    WHEN `source` = 3 THEN '人机素材'
                    WHEN `source` = 6 THEN 'AI素材'
                END
                , CASE
                    WHEN video_model_type = 1 THEN '镜头拆分模型(老模型)'
                    WHEN video_model_type = 2 THEN '剧情理解模型(新模型)'
                END
                , CASE
                    WHEN create_type = 0 THEN '无视频剪辑方式'
                    WHEN create_type = 1 THEN '高光剪辑'
                    WHEN create_type = 2 THEN '原始剪辑'
                    WHEN create_type = 3 THEN '拼合剪辑'
                    WHEN create_type = 4 THEN '二创剪辑'
                    WHEN create_type = 5 THEN '定点剪辑'
                    WHEN create_type = 6 THEN '拆条前贴'
                    WHEN create_type = 7 THEN '拆条剪辑'
                    ELSE CONCAT('未知代码', create_type)
                END
                , CASE
                    WHEN purpose = 1 THEN '拉新'
                    WHEN purpose = 2 THEN '拉活'
                    WHEN purpose = 3 THEN '唤醒'
                    WHEN purpose = 4 THEN '收入'
                    WHEN purpose = 5 THEN '电商'
                    WHEN purpose = 6 THEN '当日拉活'
                END
                , CASE
                    WHEN `provider` = 1 THEN 'AI侧'
                    WHEN `provider` = 2 THEN '内部平台D侧'
                END
                , channel_name

            UNION ALL
            SELECT
                20260608 AS update_date
                , NULL AS material_type_name
                , NULL AS source_name
                , NULL AS video_model_type_name
                , NULL AS create_type_name
                , NULL AS purpose_name
                , NULL AS provider_name
                , NULL AS production_cnt
                , NULL AS audit_cnt
                , NULL AS pass_cnt
                , NULL AS push_cnt
                , NULL AS imp_cnt
                , NULL AS clck_cnt
                , NULL AS imp
                , NULL AS clck
                , NULL AS channel_name