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.
A simple strategy would be to use date_format(arg1, arg2)
, where arg1
is the timestamp either as formatted string, date, or timestamp and the arg2
is the format of the string (in arg1
). Refer to the SimpleDateFormat
java documentation for what is acceptable in the format argument.
So, in this case:
date_format('20141014123456789', 'yyyyMMddHHmmssSSS')
would yield the following string: '2014-10-14 12:34:56.789'
which can then be cast as timestamp:
cast(date_format('20141014123456789', 'yyyyMMddHHmmssSSS') as timestamp)
The above statement would return timestamp (as desired).