<?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: Apache Nifi: substract hours from column  value with datetime format in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Apache-Nifi-substract-hours-from-column-value-with-datetime/m-p/397983#M250029</link>
    <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;I dont see a function &lt;STRONG&gt;toNumber&lt;/STRONG&gt; in the &lt;A href="https://nifi.apache.org/docs/nifi-docs/html/record-path-guide.html" target="_self"&gt;record path syntax&lt;/A&gt; , so Im not sure how did you come up with this. It would be helpful next time if you provide the following information:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;1- input format.&lt;/P&gt;&lt;P&gt;2- screenshot of the processor configuration causing the error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As for your problem , the easiest and more efficient way - than splitting records- I can think of is&amp;nbsp; using the &lt;A href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.6.0/org.apache.nifi.processors.standard.QueryRecord/index.html" target="_self"&gt;&lt;STRONG&gt;QueryRecrod&lt;/STRONG&gt; &lt;/A&gt;processor. lets assume you have the following csv input:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;id,date_time
1234,2024-11-24 19:43:17
5678,2024-11-24 01:10:10&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can pass the input to the QueryRecord Processor with the following config:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAMSAL_0-1732554596477.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/42787i65954F37FB84C9E0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_0-1732554596477.png" alt="SAMSAL_0-1732554596477.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The query above is added as a &lt;STRONG&gt;dynamic property&lt;/STRONG&gt; which will expose new &lt;STRONG&gt;relationship&lt;/STRONG&gt; with the property name that you can use to get the desired output. The query syntax is the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;select id,TIMESTAMPADD(HOUR, -3,date_time) as date_time from flowfile&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The trick for this to work&lt;/STRONG&gt; is how you configure the CSV Reader and Writer to set the expectation on how to parse datetime fields in the reader\writer services:&lt;/P&gt;&lt;P&gt;For the &lt;STRONG&gt;CSVReader&lt;/STRONG&gt;, Make sure to set the following:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAMSAL_1-1732554925571.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/42788i615F5B996C5DAF88/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_1-1732554925571.png" alt="SAMSAL_1-1732554925571.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;CSVRecordSetWriter&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAMSAL_2-1732554979478.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/42789iC88F59E339B401D0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_2-1732554979478.png" alt="SAMSAL_2-1732554979478.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output through &lt;STRONG&gt;Result&lt;/STRONG&gt; relationship:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;id,date_time
1234,2024-11-24 16:43:17
5678,2024-11-23 22:10:10&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope that helps. If it does, please accept solution.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Nov 2024 17:24:20 GMT</pubDate>
    <dc:creator>SAMSAL</dc:creator>
    <dc:date>2024-11-25T17:24:20Z</dc:date>
    <item>
      <title>Apache Nifi: substract hours from column  value with datetime format</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Apache-Nifi-substract-hours-from-column-value-with-datetime/m-p/397938#M250023</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;Input flowFile has column "date_time" with timestamp-millis type&amp;nbsp;&lt;/P&gt;&lt;P&gt;The task is to update each value of column, by substracting 3 hours from datetime value. In fact I need to transform datetime value from timezone GMT +3 to timezone GMT +0&lt;/P&gt;&lt;P&gt;For example, value "2024-11-24 19:43:17" to be transformed in "2024-11-24 16:43:17"&lt;/P&gt;&lt;P&gt;I tried to use UpdateRecord with following script:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;format(toNumber((/date_time):minus(3600)), "yyyy-MM-dd HH:mm:ss")&lt;/P&gt;&lt;P&gt;And, as expected, transformation failed with exception: "Unrecognized token 'minus'..."&lt;/P&gt;&lt;P&gt;Operation "minus" applied to attributes values. And "date_time" is not an attribute.&lt;/P&gt;&lt;P&gt;As an alternative, I considered next way:&lt;/P&gt;&lt;P&gt;1. SplitText for splitting one FlowFile into N FlowFiles, where N - is the number of records.&lt;/P&gt;&lt;P&gt;2.UpdateAttribute to add new attribute "dateTime" for each of N flowFiles by:&amp;nbsp;&lt;BR /&gt;dateTime &amp;lt;- /date_time&lt;/P&gt;&lt;P&gt;3. UpdateRecord for each of N flowFiles with script:&amp;nbsp;/date_time &amp;lt;- ${dateTime:toNumber:minus(3600):format("yyyy-MM-dd HH:mm:ss")}&lt;/P&gt;&lt;P&gt;4.Merge N flowFiles to one FlowFile&lt;/P&gt;&lt;P&gt;But this way seem to be too complicated. Is there are more&amp;nbsp;straightforward way? ))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Nov 2024 16:54:34 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Apache-Nifi-substract-hours-from-column-value-with-datetime/m-p/397938#M250023</guid>
      <dc:creator>AndreyDE</dc:creator>
      <dc:date>2024-11-24T16:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: Apache Nifi: substract hours from column  value with datetime format</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Apache-Nifi-substract-hours-from-column-value-with-datetime/m-p/397983#M250029</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;I dont see a function &lt;STRONG&gt;toNumber&lt;/STRONG&gt; in the &lt;A href="https://nifi.apache.org/docs/nifi-docs/html/record-path-guide.html" target="_self"&gt;record path syntax&lt;/A&gt; , so Im not sure how did you come up with this. It would be helpful next time if you provide the following information:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;1- input format.&lt;/P&gt;&lt;P&gt;2- screenshot of the processor configuration causing the error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As for your problem , the easiest and more efficient way - than splitting records- I can think of is&amp;nbsp; using the &lt;A href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.6.0/org.apache.nifi.processors.standard.QueryRecord/index.html" target="_self"&gt;&lt;STRONG&gt;QueryRecrod&lt;/STRONG&gt; &lt;/A&gt;processor. lets assume you have the following csv input:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;id,date_time
1234,2024-11-24 19:43:17
5678,2024-11-24 01:10:10&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can pass the input to the QueryRecord Processor with the following config:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAMSAL_0-1732554596477.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/42787i65954F37FB84C9E0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_0-1732554596477.png" alt="SAMSAL_0-1732554596477.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The query above is added as a &lt;STRONG&gt;dynamic property&lt;/STRONG&gt; which will expose new &lt;STRONG&gt;relationship&lt;/STRONG&gt; with the property name that you can use to get the desired output. The query syntax is the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;select id,TIMESTAMPADD(HOUR, -3,date_time) as date_time from flowfile&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The trick for this to work&lt;/STRONG&gt; is how you configure the CSV Reader and Writer to set the expectation on how to parse datetime fields in the reader\writer services:&lt;/P&gt;&lt;P&gt;For the &lt;STRONG&gt;CSVReader&lt;/STRONG&gt;, Make sure to set the following:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAMSAL_1-1732554925571.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/42788i615F5B996C5DAF88/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_1-1732554925571.png" alt="SAMSAL_1-1732554925571.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;CSVRecordSetWriter&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAMSAL_2-1732554979478.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/42789iC88F59E339B401D0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_2-1732554979478.png" alt="SAMSAL_2-1732554979478.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output through &lt;STRONG&gt;Result&lt;/STRONG&gt; relationship:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;id,date_time
1234,2024-11-24 16:43:17
5678,2024-11-23 22:10:10&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope that helps. If it does, please accept solution.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2024 17:24:20 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Apache-Nifi-substract-hours-from-column-value-with-datetime/m-p/397983#M250029</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2024-11-25T17:24:20Z</dc:date>
    </item>
  </channel>
</rss>

