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

前端 未结 2 990
一向
一向 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条回答
  •  囚心锁ツ
    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)

提交回复
热议问题