Local Time Convert To UTC Time In Hive

前端 未结 5 532
忘掉有多难
忘掉有多难 2020-12-28 20:34

I searched a lot on Internet but couldn\'t find the answer. Here is my question:

I\'m writing some queries in Hive. I have a UTC timestamp and would like to change i

5条回答
  •  情歌与酒
    2020-12-28 21:15

    As far as I can tell, from_utc_timestamp() needs a date string argument, like "2014-01-15 11:21:15", not a unix seconds-since-epoch value. That might be why it is giving odd results when you pass an integer?

    The only Hive function that deals with epoch seconds seems to be from_unixtime() which gives you a timestamp string in the server timezone, which I found in /etc/sysconfig/clock - "America/Montreal" in my case.

    So you can get a UTC timestamp string via to_utc_timestamp(from_unixtime(1389802875),'America/Montreal'), and then convert to your target timezone with from_utc_timestamp()

    It all seems very torturous, particularly having to wire your server TZ into your SQL. Life would be easier if there was a from_unixtime_utc() function or something.


    Update: from_utc_timestamp() does deal with a milliseconds argument as well as a string, but then gets the conversion wrong.

    When I try from_utc_timestamp(1389802875000, 'America/Los_Angeles') it gives "2014-01-15 03:21:15" which is wrong.
    The correct answer is "2014-01-15 08:21:15" which you can get (for a server in Montreal) via from_utc_timestamp(to_utc_timestamp(from_unixtime(1389802875),'America/Montreal'), 'America/Los_Angeles')

提交回复
热议问题