<?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: Impala UDF C++ : if an error occurs, is CLOSE_FN always called ? in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-UDF-C-if-an-error-occurs-is-CLOSE-FN-always-called/m-p/62481#M72137</link>
    <description>&lt;P&gt;Yes, Close() will be called if the query fails.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Keep in mind that the same UDF can be in use from multiple threads at the same time, so any cleanup logic needs to be thread-safe and not clean up things that other threads might be using.&lt;/P&gt;</description>
    <pubDate>Tue, 05 Dec 2017 01:02:33 GMT</pubDate>
    <dc:creator>Tim Armstrong</dc:creator>
    <dc:date>2017-12-05T01:02:33Z</dc:date>
    <item>
      <title>Impala UDF C++ : if an error occurs, is CLOSE_FN always called ?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-UDF-C-if-an-error-occurs-is-CLOSE-FN-always-called/m-p/62438#M72136</link>
      <description>&lt;P&gt;I have the following UDF :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;CREATE FUNCTION myudf(string)&lt;BR /&gt;RETURNS string&lt;BR /&gt;LOCATION '/user/cloudera/myudflib.so'&lt;BR /&gt;SYMBOL='&lt;EM&gt;Process&lt;/EM&gt;'&lt;BR /&gt;PREPARE_FN='&lt;EM&gt;PrepareLibrariesAndDataStructures&lt;/EM&gt;'&lt;BR /&gt;CLOSE_FN='&lt;EM&gt;CloseLibrariesAndCleanupDataStructures&lt;/EM&gt;';&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see, my C++ UDF need for each Impala thread to initialize some libraries and data structures with the &lt;EM&gt;PrepareLibrariesAndDataStructures&lt;/EM&gt; function BEFORE the &lt;EM&gt;Process&lt;/EM&gt; function start to be called multiples times.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On the other hand, &lt;EM&gt;CloseLibrariesAndCleanupDataStructures&lt;/EM&gt; need to always be called when the corresponding Impala thread has no other &lt;EM&gt;Process&lt;/EM&gt; function to call, in order to freeup data structure and cleanup libraries.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In order to avoid memory leaks, does Cloudera Impala guarantee that when, either &lt;U&gt;the user cancel the query&lt;/U&gt;,&amp;nbsp; or either the &lt;U&gt;&lt;EM&gt;Process&lt;/EM&gt; function fails with setError()&lt;/U&gt;, the&amp;nbsp;CLOSE_FN will be still called ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In other words, can we trust Cloudera Impala, to always call CLOSE_FN when a corresponding PREPARE_FN is called ? Or must we put the data_structures/library initialization/cleanup directly in the SYMBOL &lt;EM&gt;Process&lt;/EM&gt; function to minimize the memory leaks risks ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much !&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 12:35:40 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-UDF-C-if-an-error-occurs-is-CLOSE-FN-always-called/m-p/62438#M72136</guid>
      <dc:creator>Plop564</dc:creator>
      <dc:date>2022-09-16T12:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: Impala UDF C++ : if an error occurs, is CLOSE_FN always called ?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-UDF-C-if-an-error-occurs-is-CLOSE-FN-always-called/m-p/62481#M72137</link>
      <description>&lt;P&gt;Yes, Close() will be called if the query fails.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Keep in mind that the same UDF can be in use from multiple threads at the same time, so any cleanup logic needs to be thread-safe and not clean up things that other threads might be using.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 01:02:33 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-UDF-C-if-an-error-occurs-is-CLOSE-FN-always-called/m-p/62481#M72137</guid>
      <dc:creator>Tim Armstrong</dc:creator>
      <dc:date>2017-12-05T01:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: Impala UDF C++ : if an error occurs, is CLOSE_FN always called ?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-UDF-C-if-an-error-occurs-is-CLOSE-FN-always-called/m-p/62651#M72138</link>
      <description>Thanks again !</description>
      <pubDate>Sun, 10 Dec 2017 19:17:53 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-UDF-C-if-an-error-occurs-is-CLOSE-FN-always-called/m-p/62651#M72138</guid>
      <dc:creator>Plop564</dc:creator>
      <dc:date>2017-12-10T19:17:53Z</dc:date>
    </item>
  </channel>
</rss>

