<?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 How to run certain MySQL queries based on records in a FlowFile? in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/How-to-run-certain-MySQL-queries-based-on-records-in-a/m-p/384080#M245259</link>
    <description>&lt;P&gt;I'm writing a flow in Apache NiFi. In the problematic part, I have a Flow File containing several records and a table (&lt;EM&gt;table 1&lt;/EM&gt;) in MySQL Server which need to be updated. Every record in Flow File can be mapped to a row in table 1 based on values in a&amp;nbsp;&lt;STRONG&gt;key column&lt;/STRONG&gt;. Now I want to achieve the following goals:&lt;/P&gt;&lt;P&gt;1. Update fields in the matched row using field values in records as long as they are different.&lt;/P&gt;&lt;P&gt;2. Document the changes in another MySQL table (&lt;EM&gt;table 2&lt;/EM&gt;), which has columns: &lt;STRONG&gt;the mentioned&amp;nbsp;key column&lt;/STRONG&gt;, &lt;STRONG&gt;date when field changes&lt;/STRONG&gt;, &lt;STRONG&gt;revision id&amp;nbsp;&lt;/STRONG&gt;(a column from the record in Flow File),&amp;nbsp;&lt;STRONG&gt;field id&lt;/STRONG&gt; (i.e. which field has been changed. I have a table which maps column names to field id, FYI), &lt;STRONG&gt;old value&lt;/STRONG&gt;, &lt;STRONG&gt;new value&lt;/STRONG&gt;)&lt;/P&gt;&lt;P&gt;For example, if a record in the Flow File is:&lt;/P&gt;&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;{&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;'key': 1234, 'field_1': 'new_1', 'field_2': 'new_2', field_3': 'no_change_3'&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;}&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;and the corresponding row in table 1 is:&lt;/P&gt;&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;{&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;'key': 1234,&amp;nbsp;'field_1': 'old_1', 'field_2': 'old_2', field_3': 'no_change_3'&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;}&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;After processing, the row in table 1 should become:&lt;/P&gt;&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;{&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;'key': 1234, 'field_1': 'new_1', 'field_2': 'new_2', field_3': 'no_change_3'&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;}&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;and table 2 should have 2 new rows:&lt;/P&gt;&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;{&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;'key': 1234, 'date': 'some date', 'revision_id': 'some revision id', 'field_id': &lt;FONT color="#FF00FF"&gt;1&lt;/FONT&gt;, 'old_value': &lt;FONT color="#FF00FF"&gt;'old_1'&lt;/FONT&gt;, 'new_value': &lt;FONT color="#FF00FF"&gt;'new_1'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;},&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;{&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;'key': 1234, 'date': 'some date', 'revision_id': 'some revision id', 'field_id': &lt;FONT color="#FF00FF"&gt;2&lt;/FONT&gt;, 'old_value': &lt;FONT color="#FF00FF"&gt;'old_2'&lt;/FONT&gt;, 'new_value': &lt;FONT color="#FF00FF"&gt;'new_2'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;}&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;I used &lt;STRONG&gt;PutDatabaseRecord&lt;/STRONG&gt; before to do the update, but in this way, I could not achieve the second goal as the Processor seems not allow for customized queries.&lt;/P&gt;&lt;P&gt;Is there a way to achieve my purpose here?&lt;/P&gt;</description>
    <pubDate>Wed, 28 Feb 2024 07:17:50 GMT</pubDate>
    <dc:creator>iriszhuhao</dc:creator>
    <dc:date>2024-02-28T07:17:50Z</dc:date>
  </channel>
</rss>

