How to convert .net DateTime.Ticks to Hive DateTime in query?

泪湿孤枕 提交于 2019-12-11 13:52:07

问题


I have log file with a column in DateTime.Ticks (635677577653488758) which i am trying to convert it to Date in Hadoop Hive.

First i tried the code block below on MySql and it worked. But the same code didn't work in Hive because date_add function works with INT.

SELECT DATE_ADD('2001-01-01 00:00:00', INTERVAL (MAX(f.date) - 631139040000000000)/10 MICROSECOND);

Then i will format it like this...

SELECT DATE_FORMAT(MyDateFromTicks, '%Y-%m-%dT%T.%fZ');

How can i achieve this?

Thank you.


回答1:


I've found the solution. I am writing it down here so if anyone comes this far can check the answer :)

My Ticks: 635683895215023579

EPOCH Ticks: 621355968000000000

SELECT FROM_UNIXTIME(CAST((635683895215023579 - 621355968000000000)/10000000 as BIGINT),'yyyy-MM-dd\'T\'HH:mm:ss.SSSZ');



回答2:


write an UDF in java .. Use SimpleDateFormat class to convert the data into date



来源:https://stackoverflow.com/questions/30502264/how-to-convert-net-datetime-ticks-to-hive-datetime-in-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!