Apache Hive:如何将字符串转换为时间戳? [英] Apache Hive: How to convert string to timestamp?
本文介绍了Apache Hive:如何将字符串转换为时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将REC_TIME
列中的字符串转换为蜂巢中的时间戳格式.
I'm trying to convert the string in REC_TIME
column to a timestamp format in hive.
例如: Sun Jul 31 UTC 2016 => 2016-07-31 09:28:20
Ex: Sun Jul 31 09:28:20 UTC 2016 => 2016-07-31 09:28:20
SELECT xxx, UNIX_TIMESTAMP(REC_TIME, "E M dd HH:mm:ss z yyyy") FROM wlogs LIMIT 10;
当我执行上述SQL时,它返回NULL值.
When I execute the above SQL it returns a NULL value.
推荐答案
尝试一下:
select from_unixtime(unix_timestamp("Sun Jul 31 09:28:20 UTC 2016","EEE MMM dd HH:mm:ss zzz yyyy"));
如果您的配置单元群集具有UTC时区,则此方法很好.假设您的服务器位于CST中,那么您需要执行以下操作才能到达UTC;
This works fine if your hive cluster has UTC timezone. Say suppose your server is in CST then you need to do as below to get to UTC;
select to_utc_timestamp(from_unixtime(unix_timestamp("Sun Jul 31 09:28:20 UTC 2016","EEE MMM dd HH:mm:ss zzz yyyy")),'CST');
希望这会有所帮助.
编辑 配置单元的日期函数对模式使用JAVA简单的日期格式器.有关模式,请参考此.
EDIT Hive date functions use the JAVA simple date formater for the patterns . Refer this for the patterns.
这篇关于Apache Hive:如何将字符串转换为时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文