【问题标题】:Hive - Convert epoch time (ms - 13 digit) to timestamp till milliseconds in hive sqlHive - 将纪元时间(ms - 13 位)转换为时间戳,直到 hive sql 中的毫秒
【发布时间】:2021-03-09 13:19:07
【问题描述】:

我需要从 hive 查询中的纪元时间戳获取完整的时间戳。

For example 
epoch time      --- 1606407266850
timestamp value --- 2020-11-26 21:44:26 
expected value  --- 2020-11-26 21:44:26.850

我在 hive 中的方法:

Select timestamp(concat(from_unixtime(CAST(lastModifiedOn AS BIGINT),'yyyy-MM-dd HH:mm:ss'),".",CAST(lastModifiedOn AS BIGINT)%1000),'yyyy-MM-dd HH:mm:ss.SSS')
from db.table1

我的问题:我们是否有更好的方法来获取直到毫秒的时间戳值?我们可以轻松获得第二名的价值。

【问题讨论】:

    标签: sql hive hiveql hortonworks-data-platform epoch


    【解决方案1】:
    select cast(lastModifiedOn/1000 as timestamp);
    

    无法指定精度,但会将时间戳保持在最高精度

    【讨论】:

    • 谢谢mck,请在下方评论select cast(cast('1606407266850' AS BIGINT)/1000 as timestamp) ms,-- Giving correct results with ms (2020-11-26 16:14:26.85 ) cast(cast('1606476624' AS BIGINT) as timestamp) sec; -- wrong results (1970-01-19 14:14:36.624)我们可以做一些关于纪元秒的事情
    • 标准纪元时间以秒为单位。您的非标准纪元时间 1606407266850 以毫秒为单位,但 1606476624 以秒为单位。除非您执行 case when
    猜你喜欢
    • 2017-11-23
    • 1970-01-01
    • 2021-03-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-07
    • 1970-01-01
    • 2018-05-04
    • 2012-03-08
    相关资源
    最近更新 更多