【hive优化】hive的CBO优化提前过滤导致脚本报错案例
·
1.案例:
1.1 代码
set hive.execution.engine = mr;
select coalesce(if(tt.create_time = '', null, tt.create_time), '未知') as create_time -- 创建时间
, coalesce(if(tt.update_time = '', null, tt.update_time), '未知') as update_time -- 更新时间
, coalesce(if(tt.contacts_ways_type_id = '', null, tt.contacts_ways_type_id),
'未知') as contacts_ways_type_id -- 联系方式类型,1:手机2:微信3:邮箱4:5:单位地址
, coalesce(if(tt.contacts_ways_decode = '', null, tt.contacts_ways_decode),
'未知') as contacts_ways_decode -- 解密联系方式
, coalesce(if(tt.contacts_ways = '', null, tt.contacts_ways), '未知') as contacts_ways -- 联系方式
, coalesce(if(tt.contacts_id = '', null, tt.contacts_id), '未知') as contacts_id -- 联系人ID
, coalesce(if(tt.contacts_name = '', null, tt.contacts_name), '未知') as contacts_name -- 联系人名称
, coalesce(if(tt.contacts_type_id = '', null, tt.contacts_type_id),
'未知') as contacts_type_id -- 联系人类型:1:医生、2:代表
from
(-- 医生联系方式1
select cast(a.create_time as string) as create_time -- 创建时间
, cast(a.update_time as string) as update_time -- 更新时间
, cast(a.contacts_ways_type_id as string) as contacts_ways_type_id -- 联系方式类型,1:手机2:微信3:邮箱4:5:单位地址
, cast(rpt.nx_decode(a.contacts_ways) as string) as contacts_ways_decode -- 解密联系方式
, cast(a.contacts_ways as string) as contacts_ways -- 联系方式
, cast(a.contact_id as string) as contacts_id -- 联系人ID
, cast(b.hcp_name as string) as contacts_name
, cast(a.contacts_type_id as string) as contacts_type_id -- 联系人类型:1:医生、2:代表
from
(
select create_time as create_time -- 创建时间
, update_time as update_time -- 更新时间
, 0 as is_effec -- 是否有效
, contact_type as contacts_ways_type_id -- 联系方式类型,1:手机2:微信3:邮箱4:5:单位地址
, contact_info as contacts_ways -- 联系方式
, global_code as contact_id -- 联系人ID
, 1 as contacts_type_id -- 联系人类型:1:医生、2:代表
from ods.ods_ndc_hcp_contact_biz_da
where pt = '20241118'
and src_type not in (-7)
and status not in (1, 3)
and contact_info not regexp '测试'
and contact_type not in (6)
and contact_info not regexp '1[34578]\d{9}'
) a
inner join
(-- 医生信息
select global_code as hcp_id
, hcp_full_name as hcp_name
from ods.ods_ndc_hcp_info_biz_da
where pt = '20241118'
) b
on a.contact_id = b.hcp_id
) tt
where length(tt.contacts_ways_decode) = 11
1.2 报错

1.3 执行计划

1.4 问题排查过程:
如上1.1 脚本执行,报错后查看Yarn执行日志,发现报错如 1.2,大致原因是:自定义的UDF函数传入了错误的参数。
1.4.1 查看错误数据

在查找错误数据后发现错误数据的 [status = 1],奇怪,数据不是被过滤掉了么,如下图,怎么还会传入最后的UDF函数报错。
1.4.2 查看执行计划
查看 1.3 执行计划后,发现 length(tt.contacts_ways_decode) = 11被提前过滤,原因找到,应该是cbo自动优化导致。
1.5 解决
1.5.1 设置 set hive.cbo.enable = false;,查看执行计划

length(tt.contacts_ways_decode) = 11的条件过滤改在了在reduce阶段执行。
1.5.2 执行脚本

执行成功!!!
更多推荐

所有评论(0)