Hadoop 在配置单元中将字符串转换为时间戳
我的配置单元表中有时间戳的以下字符串表示形式:Hadoop 在配置单元中将字符串转换为时间戳,hadoop,hive,hiveql,Hadoop,Hive,Hiveql,我的配置单元表中有时间戳的以下字符串表示形式: 20130502081559999 我需要将其转换为如下字符串: 2013-05-02 08:15:59 我尝试了以下({code}>>>{result}): 转换为时间戳,然后转换为unixtime似乎很奇怪,正确的方法是什么 编辑 我想出来了 from_unixtime(unix_timestamp(substr('20130502081559999',1,14), 'yyyyMMddHHmmss')) >>> 2013-
20130502081559999
我需要将其转换为如下字符串:
2013-05-02 08:15:59
我尝试了以下({code}>>>{result}):
转换为时间戳,然后转换为unixtime似乎很奇怪,正确的方法是什么
编辑
我想出来了
from_unixtime(unix_timestamp(substr('20130502081559999',1,14), 'yyyyMMddHHmmss')) >>> 2013-05-02 08:15:59
或
还是。。。有更好的方法吗?看起来您的格式有三毫秒。我猜,根据,您需要使用以下内容:
from_unixtime(unix_timestamp('20130502081559999', 'yyyyMMddHHmmssSSS'))
希望对您有所帮助。不确定“更好的方式”是什么意思,但您可以随时处理日期转换。假设您有这样的输入文件 file:///data/csv/temptable/temp.csv
1 2015-01-01
2 2015-10-10 12:00:00.232
3 2016-02-02
4 2015-09-12 23:08:07.124
然后,您也可以尝试这种方法:
create external table temptable(id string, datetime string) row format delimited fields terminated by '\t' stored as textfile LOCATION 'file:///data/csv/temptable';
create table mytime as select id, from_utc_timestamp(date_format(datetime,'yyyy-MM-dd HH:mm:ss.SSS'),'UTC') as datetime from temptable;
如果可用,您可以简单地使用以下语法 1) 检查配置单元安装中是否有可用的UDF
show functions;
2) 如果从_unixtime()函数中看到,则:
from_unixtime(your_timestamp_field)
这将解决问题
如果你喜欢我的答案,请添加评论 我想你的代码最好的答案似乎是减少纳秒,有没有办法保存它
show functions;
from_unixtime(your_timestamp_field)