Hive 中的日期格式转换 [英] Date Format Conversion in Hive

查看:23
本文介绍了Hive 中的日期格式转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 sql/hive 很陌生.首先,我使用以下命令将 txt 文件加载到 hive 中:

I'm very new to sql/hive. At first, I loaded a txt file into hive using:

drop table if exists Tran_data;
create table Tran_data(tran_time string, 
resort string, settled double)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '	' LINES TERMINATED BY '
';
Load data local inpath 'C:UsersmeDocuments	ransaction_data.txt' into table Tran_Data;

txt文件中的变量tran_time是这样的:10-APR-2014 15:01.加载此 Tran_data 表后,我尝试将 tran_time 转换为标准"格式,以便我可以使用 tran_time 作为 join<将此表连接到另一个表/代码> 键.所需的日期格式是yyyymmdd".我搜索了网上资源,发现了这个:unix_timestamp(substr(tran_time,1,11),'dd-MMM-yyyy')

The variable tran_time in the txt file is like this:10-APR-2014 15:01. After loading this Tran_data table, I tried to convert tran_time to a "standard" format so that I can join this table to another table using tran_time as the join key. The date format desired is 'yyyymmdd'. I searched online resources, and found this: unix_timestamp(substr(tran_time,1,11),'dd-MMM-yyyy')

基本上,我正在这样做:unix_timestamp('10-APR-2014','dd-MMM-yyyy').但是,输出为NULL".

So essentially, I'm doing this: unix_timestamp('10-APR-2014','dd-MMM-yyyy'). However, the output is "NULL".

所以我的问题是:如何将日期格式转换为标准"格式,然后进一步转换为'yyyymmdd'格式?

So my question is: how to convert the date format to a "standard" format, and then further convert it to 'yyyymmdd' format?

推荐答案

from_unixtime(unix_timestamp('20150101' ,'yyyyMMdd'), 'yyyy-MM-dd') 

这篇关于Hive 中的日期格式转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆