How to convert Java timestamp stored as bigint to timestamp in Presto?

前端 未结 2 991
一向
一向 2021-01-20 08:13

I\'ve had little luck searching for this over a couple days.

If my avro schema for data in a hive table is:

{
  \"type\" : \"record\",
  \"name\" : \         


        
相关标签:
2条回答
  • select from_unixtime(cast(event_time as bigint) / 1000000) + parse_duration(cast((cast(event_time as bigint) % 1000) as varchar) || 'ms') from TableName limit 10;

    0 讨论(0)
  • 2021-01-20 09:05

    I didn't find direct conversion from Java timestamp (number of milliseconds since 1970) to timestamp, but one can be done with to_unixtime and adding milliseconds as interval:

    presto> with t as (select cast('1497435766032' as bigint) a)
         -> select from_unixtime(a / 1000) + parse_duration(cast((a % 1000) as varchar) || 'ms') from t;
              _col0          
    -------------------------
     2017-06-14 12:22:46.032 
    (1 row)
    

    (admittedly cumbersome, but works)

    0 讨论(0)
提交回复
热议问题