<?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 Re: Hive Insert statement in NiFi - String to DateTime in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Insert-statement-in-NiFi-String-to-DateTime/m-p/173079#M45952</link>
    <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/10100/rbolla.html" nodeid="10100"&gt;@Raj B&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The toDate NiFi expression Language function expected the input to this function to define the current format of the value it is being passed.  The result is the number of milliseconds since Jan. 1st 1970.   The Format function will take a standard date of format number milliseconds since Jan 1st 1970 and convert it into the desired output format as defined in teh function.&lt;/P&gt;&lt;P&gt;Assuming you have an attribute Abc.DateTimeOfMessage with a value of 20161011075959, teh following NiFi EL statement will produce the output '2016/10/11 07:59:59':&lt;/P&gt;&lt;PRE&gt;${Abc.DateTimeOfMessage:toDate('yyyyMMddHHmmss'):format('yyyy/MM/dd HH:mm:ss')}&lt;/PRE&gt;&lt;P&gt;The above EL statement firs convert the dat you have into the standard date format (milliseconds since 1/1/1970) using the toDate function and then pass that result to the format function which converts a standard dat format into the desired output string you are looking for.&lt;/P&gt;&lt;P&gt;*** An alternative EL that will yield the sam result is:&lt;/P&gt;&lt;PRE&gt;${Abc.DateTimeOfMessage:replaceAll('^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})','$1/$2/$3 $4:$5:$6')}&lt;/PRE&gt;&lt;P&gt;The above uses the EL replaceAll function uses java capture groups to break apart the incoming function and then uses the values of those 6 capture groups to reconstruct the output in the format you want.&lt;/P&gt;&lt;P&gt;There are even more ways, but I figured this is good enough.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Matt&lt;/P&gt;</description>
    <pubDate>Sat, 12 Nov 2016 01:06:26 GMT</pubDate>
    <dc:creator>MattWho</dc:creator>
    <dc:date>2016-11-12T01:06:26Z</dc:date>
    <item>
      <title>Hive Insert statement in NiFi - String to DateTime</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Insert-statement-in-NiFi-String-to-DateTime/m-p/173076#M45949</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm trying to create Hive insert statements for NiFi's PutHiveQL processor; I've a timestamp column in the Hive table and the incoming value for this column is in string format, like 20161011075959 (no milliseconds).&lt;/P&gt;&lt;P&gt;I tried using toDate, Format, toNumber in various combinations to convert the string to DateTime format in the Hive insert statement, but the data in Hive table shows NULL value for this column regardless; can anyone tell me what's the correct way to convert string to datetime for Hive. &lt;/P&gt;&lt;P&gt;None of the below seem to work:&lt;/P&gt;&lt;P&gt;${Abc.DateTimeOfMessage:toDate("yyyyMMddHHmmss")}&lt;/P&gt;&lt;P&gt;${Abc.DateTimeOfMessage:format("yyyy/MM/dd HH:mm:ss")}&lt;/P&gt;&lt;P&gt;${Abc.DateTimeOfMessage:toDate("yyyyMMddHHmmss"):toNumber()}&lt;/P&gt;&lt;P&gt;Thanks in advance for your time.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2016 23:58:03 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Insert-statement-in-NiFi-String-to-DateTime/m-p/173076#M45949</guid>
      <dc:creator>Raj_B</dc:creator>
      <dc:date>2016-11-11T23:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Insert statement in NiFi - String to DateTime</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Insert-statement-in-NiFi-String-to-DateTime/m-p/173077#M45950</link>
      <description>&lt;P&gt;Try this &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;${dateNum:toDate("yyyyMMddHHmmss"):format("yyyy-MM-dd HH:mm:ss")}&lt;/PRE&gt;
Where dateNum is 20161011075959 (yyyyMMddHHmmss) which on formatting changes to 2016-10-11 07:59:59 (yyyy-MM-dd HH:mm:ss)</description>
      <pubDate>Sat, 12 Nov 2016 00:33:55 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Insert-statement-in-NiFi-String-to-DateTime/m-p/173077#M45950</guid>
      <dc:creator>arunak</dc:creator>
      <dc:date>2016-11-12T00:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Insert statement in NiFi - String to DateTime</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Insert-statement-in-NiFi-String-to-DateTime/m-p/173078#M45951</link>
      <description>&lt;P&gt;What do the resulting HiveQL statement (and attributes) look like? Are you using parameters (with attributes like hiveql.args.N.value and such)? If so, then it appears from looking at the code that it expects a long integer (probably days or seconds from Epoch depending on the data type) for the value, and the appropriate &lt;A target="_blank" href="http://docs.oracle.com/javase/8/docs/api/constant-values.html#java.sql.Types.BIT"&gt;JDBC type value for DATE, TIME, or TIMESTAMP&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;If parameterized statements don't work, perhaps a ReplaceText to build an explicit HiveQL statement will (such as to remove quotes from attributes which are strings, or to &lt;A target="_blank" href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types#LanguageManualTypes-Dates"&gt;cast a literal to the appropriate date type&lt;/A&gt;, etc.)&lt;/P&gt;</description>
      <pubDate>Sat, 12 Nov 2016 00:58:29 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Insert-statement-in-NiFi-String-to-DateTime/m-p/173078#M45951</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2016-11-12T00:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Insert statement in NiFi - String to DateTime</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Insert-statement-in-NiFi-String-to-DateTime/m-p/173079#M45952</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/10100/rbolla.html" nodeid="10100"&gt;@Raj B&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The toDate NiFi expression Language function expected the input to this function to define the current format of the value it is being passed.  The result is the number of milliseconds since Jan. 1st 1970.   The Format function will take a standard date of format number milliseconds since Jan 1st 1970 and convert it into the desired output format as defined in teh function.&lt;/P&gt;&lt;P&gt;Assuming you have an attribute Abc.DateTimeOfMessage with a value of 20161011075959, teh following NiFi EL statement will produce the output '2016/10/11 07:59:59':&lt;/P&gt;&lt;PRE&gt;${Abc.DateTimeOfMessage:toDate('yyyyMMddHHmmss'):format('yyyy/MM/dd HH:mm:ss')}&lt;/PRE&gt;&lt;P&gt;The above EL statement firs convert the dat you have into the standard date format (milliseconds since 1/1/1970) using the toDate function and then pass that result to the format function which converts a standard dat format into the desired output string you are looking for.&lt;/P&gt;&lt;P&gt;*** An alternative EL that will yield the sam result is:&lt;/P&gt;&lt;PRE&gt;${Abc.DateTimeOfMessage:replaceAll('^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})','$1/$2/$3 $4:$5:$6')}&lt;/PRE&gt;&lt;P&gt;The above uses the EL replaceAll function uses java capture groups to break apart the incoming function and then uses the values of those 6 capture groups to reconstruct the output in the format you want.&lt;/P&gt;&lt;P&gt;There are even more ways, but I figured this is good enough.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Matt&lt;/P&gt;</description>
      <pubDate>Sat, 12 Nov 2016 01:06:26 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Insert-statement-in-NiFi-String-to-DateTime/m-p/173079#M45952</guid>
      <dc:creator>MattWho</dc:creator>
      <dc:date>2016-11-12T01:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Insert statement in NiFi - String to DateTime</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Insert-statement-in-NiFi-String-to-DateTime/m-p/173080#M45953</link>
      <description>&lt;P&gt;Thanks &lt;A rel="user" href="https://community.cloudera.com/users/10529/akeezhadath.html" nodeid="10529"&gt;@Arun A K&lt;/A&gt;&lt;/P&gt;&lt;P&gt;That worked, also I found  ${dateNum:format("yyyy-MM-dd HH:mm:ss")}  (without toDate) working as well in my case, may be because I already have the string in the yyyyMMddHHmmss format.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Nov 2016 01:10:31 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Insert-statement-in-NiFi-String-to-DateTime/m-p/173080#M45953</guid>
      <dc:creator>Raj_B</dc:creator>
      <dc:date>2016-11-12T01:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Insert statement in NiFi - String to DateTime</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Insert-statement-in-NiFi-String-to-DateTime/m-p/173081#M45954</link>
      <description>&lt;P&gt;The HiveQL statements for the PutHiveQL processor are like this:&lt;/P&gt;&lt;PRE&gt;INSERT INTO TABLE hive_obx_etl_test( abc_datetimeofmessage , .... ) VALUES ( '${Abc.DateTimeOfMessage:format("yyyy-MM-dd HH:mm:ss")}', ....)
&lt;/PRE&gt;&lt;P&gt;I'm not using any parameters, what I'm using is a combination of UpdateAttributes and ReplaceText processors (among others) to build the exact Hive INSERT statements.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Nov 2016 01:14:56 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Insert-statement-in-NiFi-String-to-DateTime/m-p/173081#M45954</guid>
      <dc:creator>Raj_B</dc:creator>
      <dc:date>2016-11-12T01:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Insert statement in NiFi - String to DateTime</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Insert-statement-in-NiFi-String-to-DateTime/m-p/173082#M45955</link>
      <description>&lt;P&gt;Thanks &lt;A rel="user" href="https://community.cloudera.com/users/525/mclark.html" nodeid="525"&gt;@Matt&lt;/A&gt; for the explanation&lt;/P&gt;</description>
      <pubDate>Sat, 12 Nov 2016 01:20:50 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Insert-statement-in-NiFi-String-to-DateTime/m-p/173082#M45955</guid>
      <dc:creator>Raj_B</dc:creator>
      <dc:date>2016-11-12T01:20:50Z</dc:date>
    </item>
  </channel>
</rss>

