蜂巢中的日期格式转换 [英] Date Format Conversion in Hive
问题描述
drop table if exists Tran_data;
创建表Tran_data(tran_time string,
度假字符串,结算双)
ROW FORMAT DELIMITED FIELDS TERMINATED BY'\t'LINES TERMINATED BY'\\\
';
将数据本地inpath'C:\Users\me\Documents\transaction_data.txt'加载到表Tran_Data中;
txt文件中的变量 tran_time
像这样:10-APR-2014 15:01。加载此Tran_data表后,我尝试将 tran_time
转换为标准格式,以便我可以使用 tran_time
作为加入
键。所需的日期格式为'yyyymmdd'。我搜索了在线资源,发现: unix_timestamp(substr(tran_time,1,11),'dd-MMM-yyyy')
所以基本上,我这样做: unix_timestamp('10 -APR-2014','dd-MMM-yyyy')
。但是,输出为NULL。
所以我的问题是:如何将日期格式转换为标准格式,然后进一步将其转换为yyyymmdd '格式?
from_unixtime(unix_timestamp('20150101','yyyyMMdd' 'yyyy-MM-dd')
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 '\t' LINES TERMINATED BY '\n';
Load data local inpath 'C:\Users\me\Documents\transaction_data.txt' into table Tran_Data;
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')
So essentially, I'm doing this: unix_timestamp('10-APR-2014','dd-MMM-yyyy')
. However, the output is "NULL".
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')
这篇关于蜂巢中的日期格式转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!