<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Unix time with decimal to timestamp in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Unix-time-with-decimal-to-timestamp/m-p/33185#M9036</link>
    <description>&lt;P&gt;CDH 5.3.3&lt;/P&gt;&lt;P&gt;Impala 2.1.3-cdh5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Working on converting a large MySQL table into an Impala table formatted as parquet. The datetime field was causing issues so we converted it to unix time using Java's .getTime() which gave us '1397166481000' for '2014-04-10 21:48:01'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table created and everything appears good to go, but when we try to query dates things get odd...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Field: time_stamp BIGINT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now when we query this field using Impala we get different results:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from_unixtime(time_stamp,'yyyy-MM-dd HH:mm:ss.sss') --&amp;gt; &lt;FONT color="#FF0000"&gt;2011-04-06 17:10:00.000&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CAST(time_stamp AS timestamp) --&amp;gt; &lt;FONT color="#FF0000"&gt;2011-04-06 17:10:00&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CAST(CAST(strleft(CAST(time_stamp AS STRING),10) AS bigint) AS timestamp) --&amp;gt; &lt;FONT color="#008000"&gt;2014-04-10 21:48:01&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The casting BIGINT as a STRING, then lopping off the last 3 zeros, casting back to BIGINT, then casting as timestamp seems a bit excessive but I haven't been able to find the solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do I need to go back and fix things at the .getTime() level?&lt;/P&gt;</description>
    <pubDate>Fri, 16 Sep 2022 09:44:57 GMT</pubDate>
    <dc:creator>Tully</dc:creator>
    <dc:date>2022-09-16T09:44:57Z</dc:date>
    <item>
      <title>Unix time with decimal to timestamp</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Unix-time-with-decimal-to-timestamp/m-p/33185#M9036</link>
      <description>&lt;P&gt;CDH 5.3.3&lt;/P&gt;&lt;P&gt;Impala 2.1.3-cdh5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Working on converting a large MySQL table into an Impala table formatted as parquet. The datetime field was causing issues so we converted it to unix time using Java's .getTime() which gave us '1397166481000' for '2014-04-10 21:48:01'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table created and everything appears good to go, but when we try to query dates things get odd...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Field: time_stamp BIGINT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now when we query this field using Impala we get different results:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from_unixtime(time_stamp,'yyyy-MM-dd HH:mm:ss.sss') --&amp;gt; &lt;FONT color="#FF0000"&gt;2011-04-06 17:10:00.000&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CAST(time_stamp AS timestamp) --&amp;gt; &lt;FONT color="#FF0000"&gt;2011-04-06 17:10:00&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CAST(CAST(strleft(CAST(time_stamp AS STRING),10) AS bigint) AS timestamp) --&amp;gt; &lt;FONT color="#008000"&gt;2014-04-10 21:48:01&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The casting BIGINT as a STRING, then lopping off the last 3 zeros, casting back to BIGINT, then casting as timestamp seems a bit excessive but I haven't been able to find the solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do I need to go back and fix things at the .getTime() level?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 09:44:57 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Unix-time-with-decimal-to-timestamp/m-p/33185#M9036</guid>
      <dc:creator>Tully</dc:creator>
      <dc:date>2022-09-16T09:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: Unix time with decimal to timestamp</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Unix-time-with-decimal-to-timestamp/m-p/33191#M9037</link>
      <description>&lt;P&gt;Impala automatically converts STRING literals of the correct format into TIMESTAMP values. I belive you don`t need to convert to unix time&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Timestamp values are accepted in the format YYYY-MM-DD HH:MM:SS.sssssssss, and can consist of just the date, or just the time, with or without the fractional second portion. For example, you can specify TIMESTAMP values such as' 2011-04-10', '21:48:01', or '2011-04-10 21:48:01.000' or '2011-04-10 21:48:01'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2015 21:31:31 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Unix-time-with-decimal-to-timestamp/m-p/33191#M9037</guid>
      <dc:creator>Somu</dc:creator>
      <dc:date>2015-10-20T21:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: Unix time with decimal to timestamp</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Unix-time-with-decimal-to-timestamp/m-p/33217#M9038</link>
      <description>&lt;P&gt;Turns out that dividing by 1000 solves the issue:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;CAST(tp.time_stamp/1000 AS timestamp)&lt;/PRE&gt;&lt;P&gt;which outputs the correct date and time. I still find it odd that datetime from mysql gets stored as TIMESTAMP_MILLIS --&amp;gt; int64 in parquet and bigint for the field in impala which can't be converted back to datetime without an extra step, but, things work now...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2015 15:59:31 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Unix-time-with-decimal-to-timestamp/m-p/33217#M9038</guid>
      <dc:creator>Tully</dc:creator>
      <dc:date>2015-10-21T15:59:31Z</dc:date>
    </item>
  </channel>
</rss>

