# 任务：将两个商品数据源（精细采集和泛化采集）合并，对每个字段生成质量评分。输入表：ads_sec_ec_su (HiveSQL)

## Prompt
任务目标：将两个商品数据源（精细采集表 hi 和泛化采集表 extensive）按日期分区过滤后 UNION ALL 合并，对合并后的每条记录的每个字段生成质量评分（0/1），输出到评分结果表。

输入：
- internal_platform_db.ads_sec_ec_sup_ec_tele_item_hi_query_engine_140（精细采集表，小时分区 p_hour）
- internal_platform_db.ads_sec_ec_sup_ec_tele_security_platform_lk_extensive_item_query_engine_140（泛化采集表，日分区 p_date）
- 第三个输入表 internal_platform_db.ads_sec_ec_sup_ec_tele_item_score_query_engine_140 在本任务中不使用

处理规则：
1. 过滤条件：
   - hi 表：p_hour >= '2026060800' AND p_hour < '2026060900'
   - extensive 表：p_date = '20260608'

2. UNION ALL 前的字段映射（两表字段不完全一致）：
   - hi 表：使用 sale_price，新增 source_type='精细采集'
   - extensive 表：使用 price（映射为 sale_price），新增 source_type='泛化采集'
   - 其他字段直接对齐

3. is_exp 派生规则（是否交付）：
   - 精细采集来源：required_quality_score=1 AND status=1 → 1，否则 0
   - 泛化采集来源：required_quality_score=1 → 1，否则 0

4. is_off_shelf 派生规则（是否下架）：status<>1 → 1，否则 0

5. 质量评分字段生成规则（所有字段名加 _score 后缀，除 uniqu_id 外）：
   - STRING 类型字段（id/name/url/shop_uniqu_id/shop_name/shop_url/platform_name/task_id/batch_id）：coalesce(field,'') <> '' → 1，否则 0
   - STRING 类型字段（property/sku_list/desc_info/main_image_url/sub_image_url/category_level1_name/category_level2_name/category_level3_name/shipping_address/price_text/detail_image_url/service_guarantee/brand_name/category_level1_original/category_level2_original/category_level3_original/brand_name_original/product_name/approval_number/ccc_certificate_number/efficacy/production_place/manufacturer/production_license_number/factory_name/factory_address/brand_authorization_image_url/main_image_ocr/sub_image_ocr/detail_image_ocr/industry_id/industry_name）：coalesce(field,'') = '' → 0，否则 1
   - 非空判断字段（status/sale_price/sale_qty/stock_qty/category_level1_id/category_level2_id/category_level3_id/shop_id/platform_id/brand_id/comments_cnt/high_remark_cnt/med_remark_cnt/bad_remark_cnt/sku_cnt/license_collection_status/screenshot_url）：field IS NOT NULL → 1，否则 0
   - 特殊字段：
     - logo_brand_score、similarity_img_url_score、data_method_keyword_score、task_name_score：固定 NULL
     - required_quality_score、core_quality_score、other_quality_score、platform_name、source_type、is_exp、is_off_shelf：直接传递，不生成评分

输出要求：
- 输出字段顺序（共 89 字段）：p_date、uniqu_id、id_score、name_score、sub_title_score、property_score、sku_list_score、desc_info_score、url_score、status_score、price_score、sale_qty_score、stock_qty_score、main_image_url_score、sub_image_url_score、category_level1_id_score、category_level1_name_score、category_level2_id_score、category_level2_name_score、category_level3_id_score、category_level3_name_score、shop_uniqu_id_score、shop_id_score、shop_name_score、shop_url_score、platform_id_score、platform_name_score、shipping_address_score、price_text_score、flag_score、need_cutpic_score、is_ocr_score、soe_flag_score、data_channel_score、data_method_score、data_source_score、detail_image_url_score、service_guarantee_score、brand_id_score、brand_name_score、is_ad_score、is_selfoperated_score、create_time_score、task_id_score、batch_id_score、category_level1_original_score、category_level2_original_score、category_level3_original_score、brand_name_original_score、product_name_score、approval_number_score、ccc_certificate_number_score、efficacy_score、production_place_score、manufacturer_score、production_license_number_score、factory_name_score、factory_address_score、brand_authorization_image_url_score、is_virtual_score、is_invoice_score、is_guarantee_score、is_free_ship_score、comments_cnt_score、industry_id_score、industry_name_score、high_remark_cnt_score、med_remark_cnt_score、bad_remark_cnt_score、main_image_ocr_score、sub_image_ocr_score、detail_image_ocr_score、ml_category_tag_score、logo_brand_score、similarity_img_url_score、sku_cnt_score、license_collection_status_score、data_method_keyword_score、task_name_score、screenshot_url_score、required_quality_score、core_quality_score、other_quality_score、platform_name、source_type、is_exp、is_off_shelf

写入要求：
- 输出表：internal_platform_db.ads_sec_ec_sup_ec_tele_item_score_cand_query_engine_140
- 写入方式：INSERT OVERWRITE，覆盖分区 p_date='20260608'
- 分区字段：p_date='20260608'（硬编码，非从源表继承）

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

## Reference Solution
insert overwrite table internal_platform_db.ads_sec_ec_sup_ec_tele_item_score_query_engine_140 partition(p_date='20260608')
with view_union as (
select uniqu_id,
id,
name,
sub_title,
property,
sku_list,
desc_info,
url,
status,
sale_price,
sale_qty,
stock_qty,
main_image_url,
sub_image_url,
category_level1_id,
category_level1_name,
category_level2_id,
category_level2_name,
category_level3_id,
category_level3_name,
shop_uniqu_id,
shop_id,
shop_name,
shop_url,
platform_id,
platform_name,
shipping_address,
price_text,
flag,
need_cutpic,
is_ocr,
soe_flag,
data_channel,
data_method,
data_source,
detail_image_url,
service_guarantee,
brand_id,
brand_name,
is_ad,
is_selfoperated,
create_time,
task_id,
batch_id,
category_level1_original,
category_level2_original,
category_level3_original,
brand_name_original,
product_name,
approval_number,
ccc_certificate_number,
efficacy,
production_place,
manufacturer,
production_license_number,
factory_name,
factory_address,
brand_authorization_image_url,
is_virtual,
is_invoice,
is_guarantee,
is_free_ship,
comments_cnt,
industry_id,
industry_name,
high_remark_cnt,
med_remark_cnt,
bad_remark_cnt,
main_image_ocr,
sub_image_ocr,
detail_image_ocr,
ml_category_tag,
sku_cnt,
license_collection_status,
screenshot_url,
required_quality_score,
core_quality_score,
other_quality_score,
'精细采集' as source_type,
case when required_quality_score = 1 and status = 1 then 1 else 0 end is_exp
from internal_platform_db.ads_sec_ec_sup_ec_tele_item_hi_query_engine_140
WHERE p_hour>='2026060800' and p_hour<'2026060900'
union all
select uniqu_id,
id,
name,
sub_title,
property,
sku_list,
desc_info,
url,
status,
price as sale_price,
sale_qty,
stock_qty,
main_image_url,
sub_image_url,
category_level1_id,
category_level1_name,
category_level2_id,
category_level2_name,
category_level3_id,
category_level3_name,
shop_uniqu_id,
shop_id,
shop_name,
shop_url,
platform_id,
platform_name,
shipping_address,
price_text,
flag,
need_cutpic,
is_ocr,
soe_flag,
data_channel,
data_method,
data_source,
detail_image_url,
service_guarantee,
brand_id,
brand_name,
is_ad,
is_selfoperated,
create_time,
task_id,
batch_id,
category_level1_original,
category_level2_original,
category_level3_original,
brand_name_original,
product_name,
approval_number,
ccc_certificate_number,
efficacy,
production_place,
manufacturer,
production_license_number,
factory_name,
factory_address,
brand_authorization_image_url,
is_virtual,
is_invoice,
is_guarantee,
is_free_ship,
comments_cnt,
industry_id,
industry_name,
high_remark_cnt,
med_remark_cnt,
bad_remark_cnt,
main_image_ocr,
sub_image_ocr,
detail_image_ocr,
ml_category_tag,
sku_cnt,
license_collection_status,
screenshot_url,
required_quality_score,
core_quality_score,
other_quality_score,
'泛化采集' as source_type,
case when required_quality_score=1 then 1 else 0 end as is_exp
from internal_platform_db.ads_sec_ec_sup_ec_tele_security_platform_lk_extensive_item_query_engine_140
where(p_date='20260608')
)
select
uniqu_id                                                                          as uniqu_id,
case when coalesce(id,'') <> '' then 1 else 0 end                                        as id_socre,
case when coalesce(name,'') <> '' then 1 else 0 end                                      as name_socre,
case when coalesce(sub_title,'') <> '' then 1 else 0 end                                 as sub_title_socre,
case when coalesce(property, '') = '' then 0 else 1 end                           as property_socre,
case when coalesce(sku_list, '') = '' then 0 else 1 end                           as sku_list_socre,
case when coalesce(desc_info, '') = '' then 0 else 1 end                          as desc_info_socre,
case when coalesce(url,'') <> '' then 1 else 0 end                                       as url_socre,
case when status is not null then 1 else 0 end                                    as status_socre,
case when sale_price is not null then 1 else 0 end                                as price_socre,
case when sale_qty is not null then 1 else 0 end                                  as sale_qty_socre,
case when stock_qty is not null then 1 else 0 end                                 as stock_qty_socre,
case when coalesce(main_image_url, '') = '' then 0 else 1 end                     as main_image_url_socre,
case when coalesce(sub_image_url, '') = '' then 0 else 1 end                      as sub_image_url_socre,
case when category_level1_id is not null then 1 else 0 end                        as category_level1_id_socre,
case when coalesce(category_level1_name, '') = '' then 0 else 1 end               as category_level1_name_socre,
case when category_level2_id  is not null then 1 else 0 end                       as category_level2_id_socre,
case when coalesce(category_level2_name, '') = '' then 0 else 1 end               as category_level2_name_socre,
case when category_level3_id    is not null then 1 else 0 end                     as category_level3_id_socre,
case when coalesce(category_level3_name, '') = '' then 0 else 1 end               as category_level3_name_socre,
case when coalesce(shop_uniqu_id,'') <> '' then 1 else 0 end                             as shop_uniqu_id_socre,
case when coalesce(shop_id, '') = '' then 0 else 1 end                            as shop_id_socre,
case when coalesce(shop_name,'') <> '' then 1 else 0 end                                 as shop_name_socre,
case when coalesce(shop_url,'') <> '' then 1 else 0 end                                  as shop_url_socre,
case when platform_id is not null then 1 else 0 end                               as platform_id_socre,
case when coalesce(platform_name,'') <> '' then 1 else 0 end                             as platform_name_socre,
case when coalesce(shipping_address, '') = '' then 0 else 1 end                   as shipping_address_socre,
case when coalesce(price_text, '') = '' then 0 else 1 end                         as price_text_socre,
case when flag is not null then 1 else 0 end                                      as flag_socre,
case when need_cutpic is not null then 1 else 0 end                               as need_cutpic_socre,
case when is_ocr is not null then 1 else 0 end                                    as is_ocr_socre,
case when soe_flag is not null then 1 else 0 end                                  as soe_flag_socre,
case when data_channel is not null then 1 else 0 end                              as data_channel_socre,
case when data_method is not null then 1 else 0 end                               as data_method_socre,
case when data_source is not null then 1 else 0 end                               as data_source_socre,
case when coalesce(detail_image_url, '') = '' then 0 else 1 end                   as detail_image_url_socre,
case when coalesce(service_guarantee, '') = '' then 0 else 1 end                  as service_guarantee_socre,
case when brand_id is not null then 1 else 0 end                                  as brand_id_socre,
case when coalesce(brand_name, '') = '' then 0 else 1 end                         as brand_name_socre,
case when is_ad is not null then 1 else 0 end                                     as is_ad_socre,
case when is_selfoperated is not null then 1 else 0 end                           as is_selfoperated_socre,
case when create_time is not null then 1 else 0 end                               as create_time_socre,
case when coalesce(task_id,'') <> '' then 1 else 0 end                                   as task_id_socre,
case when coalesce(batch_id,'') <> '' then 1 else 0 end                                  as batch_id_socre,
case when coalesce(category_level1_original, '') = '' then 0 else 1 end           as category_level1_original_socre,
case when coalesce(category_level2_original, '') = '' then 0 else 1 end           as category_level2_original_socre,
case when coalesce(category_level3_original, '') = '' then 0 else 1 end           as category_level3_original_socre,
case when coalesce(brand_name_original, '') = '' then 0 else 1 end                as brand_name_original_socre,
case when coalesce(product_name, '') = '' then 0 else 1 end                       as product_name_socre,
case when coalesce(approval_number, '') = '' then 0 else 1 end                    as approval_number_socre,
case when coalesce(ccc_certificate_number, '') = '' then 0 else 1 end             as ccc_certificate_number_socre,
case when coalesce(efficacy, '') = '' then 0 else 1 end                           as efficacy_socre,
case when coalesce(production_place, '') = '' then 0 else 1 end                   as production_place_socre,
case when coalesce(manufacturer, '') = '' then 0 else 1 end                       as manufacturer_socre,
case when coalesce(production_license_number, '') = '' then 0 else 1 end          as production_license_number_socre,
case when coalesce(factory_name, '') = '' then 0 else 1 end                       as factory_name_socre,
case when coalesce(factory_address, '') = '' then 0 else 1 end                    as factory_address_socre,
case when coalesce(brand_authorization_image_url, '') = '' then 0 else 1 end      as brand_authorization_image_url_socre,
case when is_virtual is not null then 1 else 0 end                                as is_virtual_socre,
case when is_invoice   is not null then 1 else 0 end                              as is_invoice_socre,
case when is_guarantee is not null then 1 else 0 end                              as is_guarantee_socre,
case when is_free_ship is not null then 1 else 0 end                              as is_free_ship_socre,
case when comments_cnt is not null then 1 else 0 end                              as comments_cnt_socre,
case when coalesce(industry_id, '') = '' then 0 else 1 end                        as industry_id_socre,
case when coalesce(industry_name, '') = '' then 0 else 1 end                      as industry_name_socre,
case when high_remark_cnt is not null then 1 else 0 end                           as high_remark_cnt_socre,
case when med_remark_cnt is not null then 1 else 0 end                            as med_remark_cnt_socre,
case when bad_remark_cnt is not null then 1 else 0 end                            as bad_remark_cnt_socre,
case when coalesce(main_image_ocr, '') = '' then 0 else 1 end                     as main_image_ocr_socre,
case when coalesce(sub_image_ocr, '') = '' then 0 else 1 end                      as sub_image_ocr_socre,
case when coalesce(detail_image_ocr, '') = '' then 0 else 1 end                   as detail_image_ocr_socre,
case when ml_category_tag is not null then 1 else 0 end                           as ml_category_tag_socre,
null                                                                              as logo_brand_socre,
null                                                                              as similarity_img_url_socre,
case when sku_cnt is not null then 1 else 0 end                                   as sku_cnt_socre,
case when license_collection_status is not null then 1 else 0 end                 as license_collection_status_socre,
null                                                                              as data_method_keyword_socre,
null                                                                              as task_name_socre,
case when screenshot_url is not null then 1 else 0 end                            as screenshot_url_socre,
required_quality_score,
core_quality_score,
other_quality_score,
platform_name,
source_type,
is_exp,
case when status <>1 then 1 else 0 end as is_off_shelf
from view_union