Hive ORC格式的配置问题

这个问题有点不好描述,当Hive表是ORC格式时,因为特定的某些字段、类型、where条件,写入到表中的数据会缺失几条,用presto执行同样的条件是正常的

以下面这个sql为例,导致出问题的字段和条件都标记出来了(吐槽下,本来是加一个字段的需求,然后数据突然不对了…泪崩

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
insert overwrite table deleteme_idl_pay_refund_class_2c_class
SELECT
t1.f_ds
,t1.incometype
,t1.orderid
,t1.preincome
,t1.income
,t1.couponcode
-- 这个字段很神奇,如果is_2b是int类型,查询是对的,但是插入到表中时,会丢数据
-- ,cast(is_2b as string) as is_2b
,t1.shipdate
,t1.orderdate
,t1.refunddate
,t1.appd
,t1.start_date
,t1.end_date
,t1.rn_asc
,t1.rn_desc
,t1.life_type
,t1.active_terminal
,t1.app_tag
,t1.resp_type
,t1.resp_source_bu
,t1.resp_source_appd
,t1.resp_source_cate
,t1.resp_source_msg
,t1.resp_source_msg_type
-- 这也是个妖孽的字段,加上之后会照成数据不对,少数据。
-- ,if(t1.reg_is_aso=1,t1.reg_ad_source_name,'非ASO') as reg_ad_source_name
FROM class.idl_pay_refund_class_class t1
WHERE datediff(t1.f_ds,t1.start_date)>=0
AND datediff(t1.f_ds,t1.start_date)<=30
AND t1.is_2b=0
-- 这个地方不能用not in,用not in的话会造成数据不对,很奇怪
AND t1.order_kind!='2'
and reg_is_aso != 1
and f_ds ='2021-02-11'

解决办法:

1
set hive.vectorized.execution.enabled=false;

这个值默认就是false,因为当时textfile迁移成orc表时,为了提高执行效率,就把参数改成了true,然后就埋了这个坑

至于为什么要从textfile转成ORC,可以参考下面文章中介绍的ORC压缩比。相比textfile,orc文件能节省3倍的空间,压缩比还是很惊人的,同时还可以节省很多计算资源。

关于原因这里就不再累述,参考下面的链接。

参数解释:
https://www.docs4dev.com/docs/zh/apache-hive/3.1.1/reference/Vectorized_Query_Execution.html

ORC文档:
http://lxw1234.com/archives/2016/04/630.htm
https://www.cnblogs.com/ittangtang/p/7677912.html