我正在尝试将带有 AM/PM 的日期字符串转换为 impala 中的时间戳以检查数据转换。我的日期字符串如下:
10/07/2017 02:04:01.575000000 PM
我试图通过以下查询在 Impala 中转换它:
选择 from_unixtime(unix_timestamp((Y_date(, "MM/dd/yyyy HH:mm:ss.SSSSSSSSS 'ZZ'"(, "yyyy-MM-dd HH:mm:ss.SSSSSS 'ZZ'"( 从表中
我得到的结果是2017-10-07 02:04:01.000000 .
我只丢失了 AM/PM,但是小时部分"02"没有转换为时间戳值"14"。结果,我需要得到以下结果:
2017-10-07 14:04:01.000000 .
我使用 Impala 作为查询 Hadoop 的接口。
任何输入都会有所帮助。
谢谢
维舒
还没有找到内置函数。必须执行效率低下的双重查询,为 PM 增加 12 小时:
SELECT cast(unix_timestamp(Y_date , "dd/MM/yyyy HH:mm:ss") + 43200 as timestamp) as
FROM table_a
where instr(`datetime`,'PM') > 0
union
SELECT cast(unix_timestamp(Y_date , "dd/MM/yyyy HH:mm:ss") as timestamp) as action_time
FROM table_a
where instr(`datetime`,'AM') > 0