How to convert a string to timestamp with milliseconds in Hive

前端 未结 5 1771
猫巷女王i
猫巷女王i 2021-02-04 11:27

I have a string \'20141014123456789\' which represents a timestamp with milliseconds that I need to convert to a timestamp in Hive (0.13.0) without losing the milliseconds.

5条回答
  •  抹茶落季
    2021-02-04 11:54

    I don't think this can be done without being messy. Because according to the unix_timestamp() function documentation it returns the time is seconds and hence will omit the milliseconds part.

    "Convert time string with given pattern to Unix time stamp (in seconds), return 0 if fail: unix_timestamp('2009-03-20', 'yyyy-MM-dd') = 1237532400."

    Best option here would be to write a UDF to handle this is you want to avoid messy concatenations. However the concatenation (though messy) would be better to the job.

提交回复
热议问题