hive 3.1版本 和 1.2版本差异
最近新搭的平台用到了hive 3.1的版本,发现和1.2的版本用法上存在差异
hive 3.1源码

其中涉及到时间转化的两个常用函数 from_unixtime 和 unix_timestamp 两者的TimeZone不在是从hive配置或者系统配置中获取,而是直接写死的UTC
hive 1.2 最后获取依赖 rt.jar包

这样就导致了带参的from_unixtime 和 unix_timestamp 函数 结果就是以UTC来算的,而不是我们北京时间PRC
为了兼容原来的功能,我们需做代码层上的修改
如:
from_unixtime:
1.2版本:
select from_unixtime(1596988800,'yyyy-MM-dd HH:mm:ss');
3.1版本:
from_utc_timestamp(1596988800*1000L,'PRC'); //默认是yyyy-MM-dd HH:mm:ss
转化为其他格式:
date_format(from_utc_timestamp(c_timestamp*1000L,'PRC'),'yyyy-MM-dd HH')
unix_timestamp:
1.2版本:
select unix_timestamp('2020-08-10 23:42:11','yyyy-MM-dd HH:mm:ss');
3.1版本:
unix_timestamp(to_utc_timestamp('2020-08-10 23:42:11','PRC'),'yyyy-MM-dd HH:mm:ss')
浙公网安备 33010602011771号