<?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: Nifi How to save failed sql queries with wrong data on local files after some retries in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Nifi-How-to-save-failed-sql-queries-with-wrong-data-on-local/m-p/370016#M240606</link>
    <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/104910"&gt;@danielhg1285&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;While the solution provided by &lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt; seems to be better for you and more production ready, you could also try the below things. This might work if you are using a stable statement all the time and if are not restricted to see the exact INSERT Statement but rather see the values trying to be inserted.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;- Shortly after RetryFlowFile, you can add an AttributesToJSON processor and manually define all the columns which you want to insert in the Attributes List Property. Make sure that you use the attribute name from your FlowFile (sql.args.N.value) in your correct order and you set Destination = flowfile-content. In this way, you will generate a JSON File with all the columns and all the values which you have tried to insert but failed.&lt;BR /&gt;- After AttributesToJSON, you can keep your PutFile to save your file locally on your machine, hence opening it whenever and wherever you want &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;PS: This is maybe not the best solution, due to the following reasons, but it will get you started on your track:&lt;BR /&gt;- You will need to know how many columns you have to insert and each time a new column will be added you will have to modify your AttributesToJSON processor.&lt;BR /&gt;- You will not get the exact SQL INSERT/UPDATE Statement, but a JSON File containing the column-value pair, which can easily be analyzed by anybody.&lt;/P&gt;</description>
    <pubDate>Thu, 04 May 2023 07:33:22 GMT</pubDate>
    <dc:creator>cotopaul</dc:creator>
    <dc:date>2023-05-04T07:33:22Z</dc:date>
    <item>
      <title>Nifi How to save failed sql queries with wrong data on local files after some retries</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-How-to-save-failed-sql-queries-with-wrong-data-on-local/m-p/369978#M240597</link>
      <description>&lt;P&gt;Hi all,&lt;BR /&gt;We are trying to configure a flow in Nifi where failed sql queries are saved&amp;nbsp;after some retries to local file for further analysis.&lt;/P&gt;&lt;P&gt;I already see the following links related to error handling in nifi&lt;BR /&gt;&lt;A href="https://youtu.be/nrxv65J4Ctg" target="_blank" rel="noopener"&gt;https://youtu.be/nrxv65J4Ctg&lt;/A&gt; by Steven Koon&lt;BR /&gt;&lt;A href="https://insights.1904labs.com/blog/2020-11-12-creating-an-error-retry-framework-in-nifi-part-2" target="_blank" rel="noopener"&gt;https://insights.1904labs.com/blog/2020-11-12-creating-an-error-retry-framework-in-nifi-part-2&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But those articles do not refer to &lt;STRONG&gt;PutSql&lt;/STRONG&gt; processor, I'm not sure if the case apply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The failed query in our scenario using &lt;STRONG&gt;PutSQL&lt;/STRONG&gt; processor is related to wrong registry information on origin database, giving error inserting a text value on a type bigint column on destination sql server database.&lt;/P&gt;&lt;P&gt;This is an example sql query used for inserts on destination database:&lt;/P&gt;&lt;P&gt;INSERT INTO destination (id, name, description, group_id) VALUES (100, 'Bob', 'Example query', '2151')&lt;/P&gt;&lt;P&gt;We have a wrong registry on origin database in where the group_id field have value 'null' getting the following exception on nifi logs:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;org.apache.nifi.processor.exception.ProcessException: Failed to process StandardFlowFileRecord[uuid=8fb0f61a-dda2-4101-befe-24ca18ced5c0,claim=StandardContentClaim [resourceClaim=StandardResourceClaim[id=1683132909199-67, container=default, section=67], offset=36504, length=104],offset=0,name=56638e31-2c44-4506-bac7-a38a2e612301,size=104] due to java.sql.SQLDataException: The value of the sql.args.4.value is 'null', which cannot be converted into the necessary data type&lt;BR /&gt;at org.apache.nifi.processor.util.pattern.ExceptionHandler.lambda$createOnGroupError$2(ExceptionHandler.java:226)&lt;BR /&gt;at org.apache.nifi.processor.util.pattern.ExceptionHandler.lambda$createOnError$1(ExceptionHandler.java:179)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As the error shows the reason is that the destination &lt;STRONG&gt;group_id&lt;/STRONG&gt; field is of type &lt;STRONG&gt;bigint&lt;/STRONG&gt;. We need to manage cases like that (registries with wrong data or format where the query fails).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I configured a &lt;STRONG&gt;PutFile&lt;/STRONG&gt;&amp;nbsp;processor to save the queries that failed in&amp;nbsp;&lt;STRONG&gt;PutSQL&lt;/STRONG&gt; processor after some retries, this is the content in the local file created by &lt;STRONG&gt;PutFile&lt;/STRONG&gt; &lt;SPAN&gt;processor&lt;/SPAN&gt; after running the flow.&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------&lt;BR /&gt;INSERT INTO topology_node_destination (id, natural_key, description, infotecnica_id) VALUES (?, ?, ?, ?)&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;This is the part of our flow concerning&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielhg1285_0-1683134892863.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/37473iF750FAE5DABA445B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="danielhg1285_0-1683134892863.png" alt="danielhg1285_0-1683134892863.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My questions are the following:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Is there a way to save the query with the &lt;STRONG&gt;PutFile&lt;/STRONG&gt; or another processor with the real values used by&amp;nbsp;&lt;STRONG&gt;PutSQL&lt;/STRONG&gt; processor, in a way to know the exact query that is causing the error ?&lt;/LI&gt;&lt;LI&gt;If that can not be achieved, what is the recommended practice ?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;BR /&gt;Thank you for reading.&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 20:08:35 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-How-to-save-failed-sql-queries-with-wrong-data-on-local/m-p/369978#M240597</guid>
      <dc:creator>danielhg1285</dc:creator>
      <dc:date>2023-05-03T20:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi How to save failed sql queries with wrong data on local files after some retries</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-How-to-save-failed-sql-queries-with-wrong-data-on-local/m-p/369979#M240598</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/104910"&gt;@danielhg1285&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/103151"&gt;@cotopaul&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;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/35454"&gt;@MattWho&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>Wed, 03 May 2023 17:46:15 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-How-to-save-failed-sql-queries-with-wrong-data-on-local/m-p/369979#M240598</guid>
      <dc:creator>DianaTorres</dc:creator>
      <dc:date>2023-05-03T17:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi How to save failed sql queries with wrong data on local files after some retries</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-How-to-save-failed-sql-queries-with-wrong-data-on-local/m-p/370001#M240602</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;It seems like you are generating your SQL from JSONToSQL kind of processor and then using PUT SQL to execute the generated SQL statement from earlier processor , is this correct? If that is the case I dont think there is an easy way to capture the actual values in the SQL statement as they are expected to be part of the generated sql flow file attribute in the format of "sql.args.N.value" based on the PUTSQL documentation. The only suggestion I have to overcome such thing is to write your custom code inside ExecuteScript processpr after the "retries-exceeded"&amp;nbsp; relationship to replace the place holders (?,?,?..) in the flowfile content with sql.args.N.value attribute where the N = place holder Index + 1, so you have to write some logic to extract the place holder , save into variable , split the variable using (,), loop through the array of "?", construct new variable with sql.args.[i+1]ivalue , when the loop finish replace the place holder string with the new value string , then store new result into new flowfile content and send to success. For more info on writing custom script using ExecuteScript :&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-1/ta-p/248922" target="_blank"&gt;https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-1/ta-p/248922&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-2/ta-p/249018" target="_blank"&gt;https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-2/ta-p/249018&lt;/A&gt;&lt;/P&gt;&lt;P&gt;If anyone has a better idea please feel free to provide your input.&lt;/P&gt;&lt;P&gt;If that helps please accept solution.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 01:52:49 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-How-to-save-failed-sql-queries-with-wrong-data-on-local/m-p/370001#M240602</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2023-05-04T01:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi How to save failed sql queries with wrong data on local files after some retries</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-How-to-save-failed-sql-queries-with-wrong-data-on-local/m-p/370016#M240606</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/104910"&gt;@danielhg1285&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;While the solution provided by &lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt; seems to be better for you and more production ready, you could also try the below things. This might work if you are using a stable statement all the time and if are not restricted to see the exact INSERT Statement but rather see the values trying to be inserted.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;- Shortly after RetryFlowFile, you can add an AttributesToJSON processor and manually define all the columns which you want to insert in the Attributes List Property. Make sure that you use the attribute name from your FlowFile (sql.args.N.value) in your correct order and you set Destination = flowfile-content. In this way, you will generate a JSON File with all the columns and all the values which you have tried to insert but failed.&lt;BR /&gt;- After AttributesToJSON, you can keep your PutFile to save your file locally on your machine, hence opening it whenever and wherever you want &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;PS: This is maybe not the best solution, due to the following reasons, but it will get you started on your track:&lt;BR /&gt;- You will need to know how many columns you have to insert and each time a new column will be added you will have to modify your AttributesToJSON processor.&lt;BR /&gt;- You will not get the exact SQL INSERT/UPDATE Statement, but a JSON File containing the column-value pair, which can easily be analyzed by anybody.&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 07:33:22 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-How-to-save-failed-sql-queries-with-wrong-data-on-local/m-p/370016#M240606</guid>
      <dc:creator>cotopaul</dc:creator>
      <dc:date>2023-05-04T07:33:22Z</dc:date>
    </item>
  </channel>
</rss>

