<?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  QueryRecord Get record based on max value between two columns in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Apache-NiFi-QueryRecord-Get-record-based-on-max-value/m-p/352152#M236450</link>
    <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt;thank you for the solution provided.&lt;/P&gt;&lt;P&gt;Testing the solution provided i was aware the sometimes the fields vaues(string) are different.&lt;/P&gt;&lt;P&gt;Sometime are in the form 20220807091252 which includes also hours and minutes, sometime 202209080.&lt;/P&gt;&lt;P&gt;So i need to have a conversion process before in order to convert into datetime.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am i right? Do you came across this?&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;</description>
    <pubDate>Tue, 13 Sep 2022 10:23:05 GMT</pubDate>
    <dc:creator>Ray82</dc:creator>
    <dc:date>2022-09-13T10:23:05Z</dc:date>
    <item>
      <title>Apache NiFi  QueryRecord Get record based on max value between two columns</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Apache-NiFi-QueryRecord-Get-record-based-on-max-value/m-p/352061#M236429</link>
      <description>&lt;P&gt;Hi community,&lt;/P&gt;&lt;P&gt;hope someone can help me on below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Flow File content is something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;[ {
"version" : "5",
"shipment_number" : "2022065597",
"situation_code" : "MLV",
"justification_code" : "CFM",
"situation_date" : "202206071253",
"new_appointment_date" : "202301081253",
}, {
"version" : "5",
"shipment_number" : "2022065597",
"situation_code" : "MLV",
"justification_code" : "CFM",
"situation_date" : "202206071252",
"new_appointment_date" : "",
} ]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to add a Query Record processor in order to grab only one JSON record for each Flow File.&lt;/P&gt;&lt;P&gt;The condition is: Get a single result with highest value of situation_date or new_appointment_date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just to explain better, the logic behind should be the following:&lt;/P&gt;&lt;P&gt;Grab the max of situation_date, the max of new_appointment_date and compare each other, then take the highest of the comparison and get entire JSON record.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In MYSQL or T-SQL it could be easier, but if i understand well Query Record is based on Apache Calcite which is not so easy for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone can point mee on the right direction?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 17:54:16 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Apache-NiFi-QueryRecord-Get-record-based-on-max-value/m-p/352061#M236429</guid>
      <dc:creator>Ray82</dc:creator>
      <dc:date>2022-09-12T17:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: Apache NiFi  QueryRecord Get record based on max value between two columns</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Apache-NiFi-QueryRecord-Get-record-based-on-max-value/m-p/352083#M236432</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;Not sure if there is better way, but in my case I was able to get the result using two QueryRecord Processors:&lt;/P&gt;&lt;P&gt;1-&amp;nbsp;&amp;nbsp; Query everything with new field&amp;nbsp; (lets call max_Date) to assign the max between "situation_date" and "new_appointment_date" on each record, in this case the query will be like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SELECT *, case when situation_date&amp;gt; new_appointment_date then situation_date else new_appointment_date end maxDate
FROM FLOWFILE
            &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2- Next QueryRecord will basically capture the max based on the max_date above from each flowfile records, as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;    SELECT *
            FROM FLOWFILE
            WHERE max_date = (
                SELECT MAX(max_date) 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;Not sure if this can be done in more efficient way, If anyone can think of better way please advise, otherwise if this works for you please accept solution.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 20:05:45 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Apache-NiFi-QueryRecord-Get-record-based-on-max-value/m-p/352083#M236432</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2022-09-12T20:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: Apache NiFi  QueryRecord Get record based on max value between two columns</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Apache-NiFi-QueryRecord-Get-record-based-on-max-value/m-p/352152#M236450</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt;thank you for the solution provided.&lt;/P&gt;&lt;P&gt;Testing the solution provided i was aware the sometimes the fields vaues(string) are different.&lt;/P&gt;&lt;P&gt;Sometime are in the form 20220807091252 which includes also hours and minutes, sometime 202209080.&lt;/P&gt;&lt;P&gt;So i need to have a conversion process before in order to convert into datetime.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am i right? Do you came across this?&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 10:23:05 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Apache-NiFi-QueryRecord-Get-record-based-on-max-value/m-p/352152#M236450</guid>
      <dc:creator>Ray82</dc:creator>
      <dc:date>2022-09-13T10:23:05Z</dc:date>
    </item>
  </channel>
</rss>

