<?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 NIFI - how to insert distinct data from the flow and refer to that data ID in other places in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/NIFI-how-to-insert-distinct-data-from-the-flow-and-refer-to/m-p/344328#M234144</link>
    <description>&lt;P&gt;Hello, I'm trying to learn NIFI so this is all new to me, I used to work with Talend and I have hard time translating to NIFI. So the main idea: For example is I have two tables in Postgresql&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table CITY :&lt;/P&gt;&lt;P&gt;ID (auto generated), &lt;FONT color="#0000FF"&gt;city_name&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Table PERSON :&lt;/P&gt;&lt;P&gt;ID (auto generated),&lt;FONT color="#993366"&gt; first_name, last_name, city_id&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I have a CSV file :&lt;/P&gt;&lt;P&gt;&lt;FONT color="#993366"&gt;first_name, last_name&lt;/FONT&gt;, &lt;FONT color="#0000FF"&gt;city_name&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Can you please explain how I can insert in tow tables from one flowfile and refer in the table PERSON to the ID of the city not the name from the table CITY.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Thank you.&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 24 May 2022 09:14:22 GMT</pubDate>
    <dc:creator>FediMannoubi</dc:creator>
    <dc:date>2022-05-24T09:14:22Z</dc:date>
    <item>
      <title>NIFI - how to insert distinct data from the flow and refer to that data ID in other places</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NIFI-how-to-insert-distinct-data-from-the-flow-and-refer-to/m-p/344328#M234144</link>
      <description>&lt;P&gt;Hello, I'm trying to learn NIFI so this is all new to me, I used to work with Talend and I have hard time translating to NIFI. So the main idea: For example is I have two tables in Postgresql&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table CITY :&lt;/P&gt;&lt;P&gt;ID (auto generated), &lt;FONT color="#0000FF"&gt;city_name&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Table PERSON :&lt;/P&gt;&lt;P&gt;ID (auto generated),&lt;FONT color="#993366"&gt; first_name, last_name, city_id&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I have a CSV file :&lt;/P&gt;&lt;P&gt;&lt;FONT color="#993366"&gt;first_name, last_name&lt;/FONT&gt;, &lt;FONT color="#0000FF"&gt;city_name&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Can you please explain how I can insert in tow tables from one flowfile and refer in the table PERSON to the ID of the city not the name from the table CITY.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Thank you.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2022 09:14:22 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NIFI-how-to-insert-distinct-data-from-the-flow-and-refer-to/m-p/344328#M234144</guid>
      <dc:creator>FediMannoubi</dc:creator>
      <dc:date>2022-05-24T09:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: NIFI - how to insert distinct data from the flow and refer to that data ID in other places</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NIFI-how-to-insert-distinct-data-from-the-flow-and-refer-to/m-p/344343#M234145</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Since you are looking for the DB auto generated ID for the City , your best option is to use the LookupRecord Processor , so the flow if your datapipeline will look something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;GetFile Processor (To the content of the CSV)&lt;/P&gt;&lt;P&gt;SplitRecord ( to split Records in the CSV)&lt;/P&gt;&lt;P&gt;[Insert the City Info to the DB First]&lt;/P&gt;&lt;P&gt;LookupRecord ( to get the ID of the City and enrich you CSV with ID. The Lookup Service should be DB Lookup Service that points to the City Table and Use City Name as Key)&lt;/P&gt;&lt;P&gt;[Finally Insert the Person Information with City ID added to the original csv record]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To Learn more about LookupRecord, you can watch this video:&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.youtube.com/watch?v=bSJ5reO8AA4" target="_blank"&gt;https://www.youtube.com/watch?v=bSJ5reO8AA4&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To learn more about the L&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2022 12:43:55 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NIFI-how-to-insert-distinct-data-from-the-flow-and-refer-to/m-p/344343#M234145</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2022-05-24T12:43:55Z</dc:date>
    </item>
    <item>
      <title>Re: NIFI - how to insert distinct data from the flow and refer to that data ID in other places</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NIFI-how-to-insert-distinct-data-from-the-flow-and-refer-to/m-p/344345#M234146</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/98126"&gt;@FediMannoubi&lt;/a&gt;&amp;nbsp;Below is a basic approach to solve.&amp;nbsp; Assuming both postgres tables are populated with rows per your example, your nifi flow would need to get the CSV (various ways to do that), once the contents of the csv are in a flowfile (i use GenerateFlowFile processor), you can use a RecordReader based processor to read the csv.&amp;nbsp; This will allow you to write SQL against the flowfile with QueryRecord to get a single value.&amp;nbsp; For example:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;SELECT city_name FROM FLOWFILE&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Next, in your flow you will need to get the city_name value into an attribute, i use EvaluateJsonPath.&amp;nbsp; After that a ExecuteSQL processor and associated DBCP Connection pool to postgres.&amp;nbsp; Then in ExecuteSQL your query is&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;SELECT city_id FROM CITY WHERE city_name=${city_name}&lt;/PRE&gt;&lt;P&gt;At the end of this flow you will have the city_name from csv, and city_id from postgres.&amp;nbsp; You can now combine or use the further downstream to suit your needs.&amp;nbsp; &amp;nbsp;INSERT is done similarly, once you have the data in flowfiles, or attributes, using the same ExecuteSQL you write an insert instead.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;My test flow looks like this, but forgive the end, as I did not actually have a postgres database setup.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-05-24 at 8.53.49 AM.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/34422iCD4CCFC09FDAB257/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2022-05-24 at 8.53.49 AM.png" alt="Screen Shot 2022-05-24 at 8.53.49 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;You can find this sample flow [&lt;A href="https://github.com/cldr-steven-matison/NiFi-Templates/blob/main/CSV%2BQueryRecord%2BExecuteSql.xml" target="_self"&gt;here&lt;/A&gt;].&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this gets you pointed in the right direction for reading csv and querying data from database.&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2022 13:02:47 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NIFI-how-to-insert-distinct-data-from-the-flow-and-refer-to/m-p/344345#M234146</guid>
      <dc:creator>steven-matison</dc:creator>
      <dc:date>2022-05-24T13:02:47Z</dc:date>
    </item>
  </channel>
</rss>

