【问题标题】:How can I convert a date in string format ("April 25, 2018" ) to timestamp in hive?如何将字符串格式的日期(“April 25, 2018”)转换为 hive 中的时间戳?
【发布时间】:2018-07-26 17:44:15
【问题描述】:

我有一个带有 string 的“日期”列,例如 April 25, 2018,我需要将其转换为时间戳值。

我可以使用 Impala 编辑器通过以下查询进行转换:

SELECT to_timestamp(concat(substr(`date`,1,3), ' ', lpad(split_part(`date`, ' ', 2), 3, '0'), ' ', split_part(`date`, ' ', 3)), 'MMM dd, yyyy') as `date` 
from A

但是当我使用 Hive 编辑器时,此查询失败并出现错误:

“无效的函数‘split_part’”

如何在 Hive/Hue 编辑器中将此字符串转换为时间戳?

【问题讨论】:

  • 输出应该是什么样的?

标签: hive hiveql impala hue


【解决方案1】:

您可以将from_unixtimeunix_timestamp 结合使用。

select from_unixtime(unix_timestamp(`date`,'MMM dd, yyyy'),'yyyy-MM-dd')

【讨论】:

    猜你喜欢
    • 2019-03-16
    • 1970-01-01
    • 1970-01-01
    • 2012-04-19
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 2016-02-01
    相关资源
    最近更新 更多