<?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: How to use query result in another query Apache NiFi in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/How-to-use-query-result-in-another-query-Apache-NiFi/m-p/394045#M248655</link>
    <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/117570"&gt;@Shalexey&lt;/a&gt;&amp;nbsp;Welcome to the Cloudera Community!&lt;BR /&gt;&lt;BR /&gt;To help you get the best possible solution, I have tagged our NiFi experts&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/35454"&gt;@MattWho&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt;&amp;nbsp; who may be able to assist you further.&lt;BR /&gt;&lt;BR /&gt;Please keep us updated on your post, and we hope you find a satisfactory solution to your query.&lt;/P&gt;</description>
    <pubDate>Thu, 26 Sep 2024 20:57:52 GMT</pubDate>
    <dc:creator>DianaTorres</dc:creator>
    <dc:date>2024-09-26T20:57:52Z</dc:date>
    <item>
      <title>How to use query result in another query Apache NiFi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-use-query-result-in-another-query-Apache-NiFi/m-p/394032#M248648</link>
      <description>&lt;P&gt;Hi, experts,&lt;/P&gt;&lt;P&gt;I need to insert data from CSV to DB. CSV file name is the same as DB table name, but table has additional primery key column, so I need to add such column in CSV. I can get max key value from DB table. Please, advise how to use this key value in flowfile. Here is my flow&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Shalexey_1-1727359094322.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/41891i4CA4AF22E6973D5D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Shalexey_1-1727359094322.png" alt="Shalexey_1-1727359094322.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 13:59:23 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-use-query-result-in-another-query-Apache-NiFi/m-p/394032#M248648</guid>
      <dc:creator>Shalexey</dc:creator>
      <dc:date>2024-09-26T13:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to use query result in another query Apache NiFi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-use-query-result-in-another-query-Apache-NiFi/m-p/394045#M248655</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/117570"&gt;@Shalexey&lt;/a&gt;&amp;nbsp;Welcome to the Cloudera Community!&lt;BR /&gt;&lt;BR /&gt;To help you get the best possible solution, I have tagged our NiFi experts&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/35454"&gt;@MattWho&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt;&amp;nbsp; who may be able to assist you further.&lt;BR /&gt;&lt;BR /&gt;Please keep us updated on your post, and we hope you find a satisfactory solution to your query.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 20:57:52 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-use-query-result-in-another-query-Apache-NiFi/m-p/394045#M248655</guid>
      <dc:creator>DianaTorres</dc:creator>
      <dc:date>2024-09-26T20:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to use query result in another query Apache NiFi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-use-query-result-in-another-query-Apache-NiFi/m-p/394118#M248668</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/117570"&gt;@Shalexey&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Your query does not contain a lot of detail around your use case, but i'll try to provide some pointers here.&lt;BR /&gt;&lt;BR /&gt;NiFi processor components have one or more defined relationships.&amp;nbsp; These relationships are where the NiFi FlowFile is routed when a processor completes its execution.&amp;nbsp; When you assign a processor relationship to more then 1 outbound connection, NiFi will clone the FlowFile how ever many times the relationship usage is duplicated.&amp;nbsp; So looking at dataflow design shared, I see you have what appears to be&amp;nbsp; "success" relationship route twice out of the UpdateAttribute processor (this means the original FlowFile is sent to one of these connections and a new cloned FlowFile is sent to the other connection).&lt;/P&gt;&lt;P&gt;So you can't simply route both these FlowFiles back to your QueryRecord processor as each would be executed against independently.&lt;BR /&gt;&lt;BR /&gt;If I am understanding your use case correctly you ingest a csv file that needs to be updated with an additional new column (primary key).&amp;nbsp; The value that will go into that new column is fetched from another DB via the ExecuteSQLRecord processor.&amp;nbsp; Problem is that the ExecuteSQLRecord processor would overwrite your csv content.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;So what you need to build is a flow that get the enhancement data (primary key) and adds it to the original csv before the putDataBaseRecord processor.&lt;BR /&gt;&lt;BR /&gt;Others might have different solution suggestions, but here is one option that comes to mind:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MattWho_0-1727456293238.png" style="width: 714px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/41916iF264B5DCC4DC5B1B/image-dimensions/714x780?v=v2" width="714" height="780" role="button" title="MattWho_0-1727456293238.png" alt="MattWho_0-1727456293238.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.27.0/org.apache.nifi.processors.standard.GetFile/index.html" target="_blank"&gt;GetFile&lt;/A&gt; --&amp;gt; Gets the original CSV file&lt;BR /&gt;&lt;A href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-update-attribute-nar/1.27.0/org.apache.nifi.processors.attributes.UpdateAttribute/index.html" target="_blank"&gt;UpdateAttribute&lt;/A&gt; --&amp;gt; sets a correlation ID (corrID = ${UUID()}) so that when FlowFile is cloned later both can be correlated to one another with this correlation ID that will be same on both.&amp;nbsp;&lt;BR /&gt;&lt;A href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.27.0/org.apache.nifi.processors.standard.ExecuteSQL/index.html" target="_blank"&gt;ExecuteSQL&lt;/A&gt; --&amp;gt; query max key DB&lt;BR /&gt;QueryRecord --&amp;gt; trim output to just needed max key&amp;nbsp;&lt;BR /&gt;&lt;A href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.27.0/org.apache.nifi.processors.standard.ExtractText/index.html" target="_blank"&gt;ExtractText&lt;/A&gt; --&amp;gt; Extract the max key value from the content to a FlowFile Attribute (maxKey).&lt;BR /&gt;&lt;A href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.27.0/org.apache.nifi.processors.standard.ModifyBytes/index.html" target="_blank"&gt;ModifyBytes&lt;/A&gt; --&amp;gt; set Remove all Content&amp;nbsp; to true to clear content from this FlowFile (does not affect FlowFile attributes.&lt;BR /&gt;&lt;A href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.27.0/org.apache.nifi.processors.standard.MergeContent/index.html" target="_blank"&gt;MergeContent&lt;/A&gt; - min num entries = 2, Correlation Attribute name = corrID, Attribute strategy&amp;nbsp; = Keep All Unique Attributes.&amp;nbsp; (This will merge both FlowFiles original and clone with same value in FlowFile attribute "corrID" into one FlowFile containing only the csv content)&lt;BR /&gt;&lt;A href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.27.0/org.apache.nifi.processors.standard.UpdateRecord/index.html" target="_blank"&gt;UpdateRecord&lt;/A&gt; --&amp;gt; Used to insert the max key value from the max key FlowFile attribute into the original CSV content. (Record reader can infer schema; however, record writer will need to have a defined schema that includes the new "primary key" column. Then you will be able to add a dynamic property to insert maxkey&amp;nbsp;flowfile attribute into the "primaryKey" csv column.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MattWho_1-1727457156154.png" style="width: 713px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/41917iAD818000D272B17D/image-dimensions/713x50?v=v2" width="713" height="50" role="button" title="MattWho_1-1727457156154.png" alt="MattWho_1-1727457156154.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.27.0/org.apache.nifi.processors.standard.PutDatabaseRecord/index.html" target="_blank"&gt;PutDatabaseRecord&lt;/A&gt; --&amp;gt; write modified csv to destination DB.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Even if this does not match up directly, maybe you will be able to apply the NiFi dataflow design concept above to solution your specific detailed use case.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Please help our community grow. If you found&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;any&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;of the suggestions/solutions provided helped you with solving your issue or answering your question, please take a moment to login and click "&lt;SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Accept as Solution&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;" on&amp;nbsp;&lt;STRONG&gt;one or more&lt;/STRONG&gt;&amp;nbsp;of them that helped.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you,&lt;BR /&gt;Matt&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2024 17:22:26 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-use-query-result-in-another-query-Apache-NiFi/m-p/394118#M248668</guid>
      <dc:creator>MattWho</dc:creator>
      <dc:date>2024-09-27T17:22:26Z</dc:date>
    </item>
  </channel>
</rss>

