创建具有不规则 date/time 格式列的 Hive table
Creating a Hive table with an irregular date/time format column
我必须从 csv 创建一个 Hive table,其中两列有一个 date/time 字段,格式如下:11/28/2018 8:35:23 PM 或11/30/2018 5:02:17 上午等 例如:
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;
但我不太确定如何处理 AM
和 PM
。我也不太确定 insert into table
语法是否正确。任何帮助将不胜感激。
使用SimpleDateFormat class 文档作为格式参考。正确的格式是
'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'))
Returns:
2018-11-28 20:35:23
Insert into table 像这样:
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;
我必须从 csv 创建一个 Hive table,其中两列有一个 date/time 字段,格式如下:11/28/2018 8:35:23 PM 或11/30/2018 5:02:17 上午等 例如:
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;
但我不太确定如何处理 AM
和 PM
。我也不太确定 insert into table
语法是否正确。任何帮助将不胜感激。
使用SimpleDateFormat class 文档作为格式参考。正确的格式是
'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'))
Returns:
2018-11-28 20:35:23
Insert into table 像这样:
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;