Datetime 创建具有不规则日期/时间格式列的配置单元表
我必须从csv创建一个配置单元表,其中两列有一个日期/时间字段,格式如下:11/28/2018 8:35:23 PM或11/30/2018 5:02:17 AM,等等。例如:Datetime 创建具有不规则日期/时间格式列的配置单元表,datetime,hadoop,hive,hiveql,simpledateformat,Datetime,Hadoop,Hive,Hiveql,Simpledateformat,我必须从csv创建一个配置单元表,其中两列有一个日期/时间字段,格式如下:11/28/2018 8:35:23 PM或11/30/2018 5:02:17 AM,等等。例如: responseid process_start process_end status 26 11/28/2018 8:35:23 PM 11/30/2018 5:02:17 AM complete 我知
responseid process_start process_end status
26 11/28/2018 8:35:23 PM 11/30/2018 5:02:17 AM complete
我知道我可以先将这些字段创建为字符串,然后执行以下操作:
insert into table newtable
select process_start, from_unixtime(unix_timestamp(process_start, 'dd-MM-yyyy HH:mm:ss')) from oldtable;
INSERT INTO TABLE newtable
select responseid,
from_unixtime(unix_timestamp(process_start, 'MM/dd/yyyy h:mm:ss a')) process_start,
from_unixtime(unix_timestamp(process_end, 'MM/dd/yyyy h:mm:ss a')) process_end,
status
from oldtable;
但是我不太清楚如何处理AM
和PM
。我也不太确定我的insert-into-table
语法是否正确。任何帮助都将不胜感激。使用类文档作为格式参考。正确的格式是
'MM/dd/yyyy h:MM:ss a'
select from_unixtime(unix_timestamp('11/28/2018 8:35:23 PM', 'MM/dd/yyyy h:mm:ss a'))
返回:
2018-11-28 20:35:23
像这样:
insert into table newtable
select process_start, from_unixtime(unix_timestamp(process_start, 'dd-MM-yyyy HH:mm:ss')) from oldtable;
INSERT INTO TABLE newtable
select responseid,
from_unixtime(unix_timestamp(process_start, 'MM/dd/yyyy h:mm:ss a')) process_start,
from_unixtime(unix_timestamp(process_end, 'MM/dd/yyyy h:mm:ss a')) process_end,
status
from oldtable;